:root {
  color-scheme: light dark;
  --canvas: #f5f5f4; --surface: #fff; --fill-1: rgba(23, 24, 26, 0.045); --fill-2: rgba(23, 24, 26, 0.09);
  --text: #17181a; --muted: #6b6a65; --border: rgba(23, 24, 26, 0.12); --inverse: #17181a; --on-inverse: #f7f7f6;
  --green: #1f9d55; --amber: #b45309; --amber-soft: rgba(255, 159, 10, 0.14); --danger: #c62833;
  --shadow: 0 1px 2px rgba(15, 15, 15, 0.04), 0 8px 24px -12px rgba(15, 15, 15, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", Inter, sans-serif;
  font-size: 15px; line-height: 1.5; background: var(--canvas); color: var(--text); -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0b0b0d; --surface: #19191c; --fill-1: rgba(255, 255, 255, 0.06); --fill-2: rgba(255, 255, 255, 0.11);
    --text: #f5f5f7; --muted: rgba(255, 255, 255, 0.6); --border: rgba(255, 255, 255, 0.14); --inverse: #f5f5f7;
    --on-inverse: #0e0f11; --green: #34d17a; --amber: #f5a524; --danger: #ff5a5f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { background: var(--canvas); overflow: hidden; }
[hidden] { display: none !important; }
h1 { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--text); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; min-height: 40px; padding: 0 14px;
  border: 0; border-radius: 12px; background: var(--fill-2); font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--inverse); color: var(--on-inverse); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 10px; }
.card { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); }
.hint { font-size: 13px; color: var(--muted); line-height: 1.65; }
.error { font-size: 13px; color: var(--danger); min-height: 1.2em; }
.row { display: flex; align-items: center; gap: 8px; }
.row.end { justify-content: space-between; margin-top: 8px; }
.stack { display: grid; gap: 12px; }

.gate { height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto; }
.gate-card { width: min(100%, 380px); padding: 28px 24px; display: grid; gap: 14px; }

.chat { height: 100dvh; max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.bar h1 { flex: 0 0 auto; }
.members { flex: 1 1 auto; display: flex; gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.members::-webkit-scrollbar { display: none; }
.chip { position: relative; flex: 0 0 auto; border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.chip .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--canvas); background: #a3a29c; }
.chip.online .dot { background: var(--green); }
.chip.waiting .dot { background: var(--amber); }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-size: 14px; font-weight: 600; flex: 0 0 auto; user-select: none; }
.avatar.emoji { background: var(--fill-2) !important; font-size: 19px; }

.log { flex: 1 1 auto; overflow-y: auto; padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; outline: none; }
.empty { margin: auto; max-width: 300px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7; }
.more { align-self: center; }
.msg { display: flex; gap: 9px; max-width: min(86%, 640px); }
.msg.owner { align-self: flex-end; flex-direction: row-reverse; }
.msg .body { display: grid; gap: 4px; min-width: 0; justify-items: start; }
.msg.owner .body { justify-items: end; }
.meta { display: flex; align-items: baseline; gap: 7px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.meta strong { font-weight: 600; color: var(--text); opacity: 0.8; }
.bubble { padding: 9px 13px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.msg.owner .bubble { background: var(--inverse); color: var(--on-inverse); box-shadow: none; }
.bubble a { text-decoration: underline; text-underline-offset: 2px; }
.bubble .at { font-weight: 600; }
.notice { margin: 0 14px 8px; padding: 9px 13px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-size: 13px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 140px; font-size: 16px; border-radius: 16px; }
.composer .btn { min-height: 42px; border-radius: 16px; }

dialog { width: min(calc(100% - 24px), 520px); max-height: calc(100dvh - 32px); margin: auto; padding: 20px; border: 0; border-radius: 22px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.4); overflow-y: auto; }
dialog[open] { display: grid; gap: 14px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.member-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.member-list li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; padding: 12px; border-radius: 14px; background: var(--fill-1); }
.member-list .avatar { grid-row: span 2; }
.member-list .name { font-weight: 600; overflow-wrap: anywhere; }
.member-list .status { font-size: 12.5px; color: var(--muted); line-height: 1.6; overflow-wrap: anywhere; }
.member-list .actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.member-list .none { display: block; color: var(--muted); font-size: 13px; background: none; padding: 0; }
.add { display: grid; gap: 8px; }
.avatar-input { width: 56px; flex: 0 0 auto; text-align: center; padding: 9px 4px; }
.ways { border: 0; padding: 0; display: grid; gap: 8px; }
.ways legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ways label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.ways input { width: auto; min-height: 0; flex: 0 0 auto; }
.ways select { width: auto; flex: 0 0 auto; min-height: 34px; padding: 4px 8px; }
#invite-text { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; line-height: 1.6; resize: vertical; }
#me-turns { width: 90px; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); max-width: calc(100% - 32px); padding: 9px 15px; border-radius: 999px; background: var(--inverse); color: var(--on-inverse); font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; z-index: 100; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
