:root {
  color-scheme: light;
  --bg: #f7f8fc;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --panel-soft: #f1f4fa;
  --text: #182033;
  --muted: #758096;
  --subtle: #a8b0c0;
  --border: rgba(44, 62, 94, 0.11);
  --accent: #5b7cfa;
  --accent-strong: #4667e8;
  --accent-soft: #edf1ff;
  --success: #1eb980;
  --danger: #e95464;
  --shadow: 0 18px 45px rgba(32, 46, 80, 0.13);
  --radius: 18px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111521;
  --panel: rgba(25, 31, 46, 0.94);
  --panel-solid: #191f2e;
  --panel-soft: #20283a;
  --text: #edf1fa;
  --muted: #9aa5ba;
  --subtle: #6e7a91;
  --border: rgba(190, 205, 238, 0.12);
  --accent: #7f98ff;
  --accent-strong: #9aabff;
  --accent-soft: rgba(91, 124, 250, 0.16);
  --success: #39d69c;
  --danger: #ff7b88;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 10% 0%, rgba(91, 124, 250, 0.08), transparent 34%),
    radial-gradient(circle at 100% 90%, rgba(139, 92, 246, 0.06), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, textarea, input { font: inherit; }
button { color: inherit; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.app { height: 100dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px 10px 15px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 20;
}
.brand { display: flex; align-items: center; min-width: 0; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 13px;
  display: grid; place-items: center; flex: 0 0 auto;
  color: #fff; background: linear-gradient(145deg, #6e8bff, #7d5df4);
  box-shadow: 0 7px 18px rgba(91, 124, 250, 0.25);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-copy { min-width: 0; display: grid; gap: 2px; }
.brand-copy strong { font-size: 14.5px; letter-spacing: 0.01em; white-space: nowrap; }
.status-button {
  border: 0; background: transparent; padding: 0; color: var(--muted);
  display: flex; align-items: center; gap: 5px; font-size: 11.5px; cursor: default;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--subtle); box-shadow: 0 0 0 3px color-mix(in srgb, var(--subtle) 14%, transparent); }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 14%, transparent); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 13%, transparent); }
.top-actions { display: flex; align-items: center; gap: 3px; }
.icon-button, .avatar-button, .composer-icon, .mini-icon {
  border: 0; background: transparent; cursor: pointer; display: grid; place-items: center;
  transition: background .18s ease, transform .18s ease, color .18s ease;
}
.icon-button { width: 34px; height: 34px; border-radius: 11px; color: var(--muted); font-size: 19px; }
.icon-button:hover { background: var(--panel-soft); color: var(--text); }
.icon-button:active, .avatar-button:active, .composer-icon:active { transform: scale(.94); }
.icon-button svg { width: 18px; height: 18px; }
.online-button { width: auto; min-width: 42px; padding: 0 7px; grid-auto-flow: column; gap: 4px; font-size: 12px; font-weight: 700; }
.avatar-button { width: 34px; height: 34px; border-radius: 11px; margin-left: 2px; color: #fff; font-weight: 700; background: var(--accent); box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }

.connection-banner {
  margin: 8px 10px 0;
  padding: 8px 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-radius: 11px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px;
}
.spinner { width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.messages-wrap { position: relative; min-height: 0; overflow: hidden; }
.messages { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 16px 13px 14px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 23%, transparent); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
.welcome-card {
  max-width: 330px; margin: 8px auto 22px; padding: 20px 20px 17px; text-align: center;
  border: 1px solid var(--border); border-radius: 22px; background: color-mix(in srgb, var(--panel-solid) 82%, transparent); box-shadow: 0 10px 35px rgba(42, 58, 92, .06);
}
.welcome-icon { width: 38px; height: 38px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 13px; background: var(--accent-soft); color: var(--accent); font-size: 18px; }
.welcome-card h1 { font-size: 15px; margin: 0 0 7px; }
.welcome-card > p { color: var(--muted); margin: 0; font-size: 12.5px; line-height: 1.65; }
.privacy-note { margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--subtle); font-size: 10.5px; }
.privacy-note svg { width: 13px; height: 13px; }

.message-row { display: flex; gap: 9px; margin: 12px 0; align-items: flex-start; animation: message-in .22s ease-out; }
.message-row.self { flex-direction: row-reverse; }
@keyframes message-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.message-avatar { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 10px; color: white; font-weight: 750; font-size: 12px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.message-body { min-width: 0; max-width: min(82%, 420px); }
.message-row.self .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-meta { display: flex; align-items: center; gap: 6px; margin: 0 3px 4px; color: var(--muted); font-size: 10.5px; min-width: 0; }
.message-row.self .message-meta { flex-direction: row-reverse; }
.message-name { color: var(--text); font-weight: 650; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-source { max-width: 105px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--subtle); }
.message-bubble {
  position: relative; border: 1px solid var(--border); border-radius: 7px 17px 17px 17px;
  padding: 9px 11px; background: var(--panel-solid); box-shadow: 0 4px 13px rgba(35, 50, 85, .045);
  line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap;
}
.message-row.self .message-bubble { color: white; border-color: transparent; background: linear-gradient(145deg, var(--accent), #6e62e9); border-radius: 17px 7px 17px 17px; }
.message-bubble a { color: var(--accent-strong); text-underline-offset: 2px; }
.message-row.self .message-bubble a { color: white; }
.reply-preview { display: block; width: 100%; border-left: 3px solid color-mix(in srgb, currentColor 55%, transparent); padding: 5px 7px; margin-bottom: 7px; border-radius: 4px 8px 8px 4px; background: color-mix(in srgb, currentColor 7%, transparent); opacity: .86; font-size: 11px; }
.reply-preview strong, .reply-preview span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview strong { margin-bottom: 2px; }
.message-actions { margin-top: 3px; opacity: 0; transition: opacity .15s ease; }
.message-row:hover .message-actions, .message-row:focus-within .message-actions { opacity: 1; }
.reply-button { border: 0; background: transparent; color: var(--subtle); font-size: 10.5px; cursor: pointer; padding: 2px 4px; }
.reply-button:hover { color: var(--accent); }
.system-message { display: flex; justify-content: center; margin: 12px 0; }
.system-message span { max-width: 90%; padding: 5px 9px; border-radius: 999px; color: var(--subtle); background: color-mix(in srgb, var(--panel-soft) 72%, transparent); font-size: 10.5px; text-align: center; }

.jump-button { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); border: 1px solid var(--border); border-radius: 999px; background: var(--panel-solid); box-shadow: var(--shadow); padding: 7px 11px; display: flex; align-items: center; gap: 5px; color: var(--accent-strong); font-size: 11px; cursor: pointer; }
.jump-button svg { width: 13px; height: 13px; }
.typing-line { min-height: 22px; padding: 1px 16px 5px; color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing-dots { display: inline-flex; gap: 2px; margin-left: 4px; vertical-align: 1px; }
.typing-dots i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; animation: typing 1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%,60%,100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-2px); opacity: 1; } }

.composer-shell { position: relative; z-index: 15; padding: 0 10px max(8px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding-top: 9px; }
.composer-icon { width: 35px; height: 38px; border-radius: 12px; color: var(--muted); flex: 0 0 auto; }
.composer-icon:hover { background: var(--panel-soft); color: var(--accent); }
.composer-icon svg { width: 20px; height: 20px; }
.input-wrap { position: relative; flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--panel-soft); border-radius: 15px; transition: border-color .18s, box-shadow .18s; }
.input-wrap:focus-within { border-color: color-mix(in srgb, var(--accent) 54%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent); }
textarea { display: block; width: 100%; min-height: 38px; max-height: 118px; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; padding: 9px 36px 9px 11px; line-height: 1.45; overflow-y: auto; }
textarea::placeholder { color: var(--subtle); }
textarea:disabled { cursor: not-allowed; opacity: .65; }
.char-count { position: absolute; right: 8px; bottom: 7px; color: var(--subtle); font-size: 9.5px; }
.char-count.warning { color: var(--danger); }
.send-button { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 13px; color: white; background: linear-gradient(145deg, var(--accent), #755eea); box-shadow: 0 7px 17px rgba(91, 124, 250, .25); cursor: pointer; transition: transform .18s, opacity .18s; }
.send-button:hover:not(:disabled) { transform: translateY(-1px); }
.send-button:active:not(:disabled) { transform: scale(.94); }
.send-button:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.send-button svg { width: 17px; height: 17px; }
.composer-hint { padding: 5px 0 0; text-align: center; color: var(--subtle); font-size: 9.5px; }
.reply-bar { margin-top: 8px; padding: 7px 8px 7px 10px; border-left: 3px solid var(--accent); border-radius: 7px 11px 11px 7px; background: var(--accent-soft); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.reply-bar div { min-width: 0; }
.reply-bar span { color: var(--accent-strong); font-size: 10.5px; }
.reply-bar p { margin: 2px 0 0; color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-icon { width: 25px; height: 25px; border-radius: 8px; color: var(--muted); font-size: 18px; }
.mini-icon:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.emoji-panel { position: absolute; left: 9px; bottom: calc(100% + 8px); width: min(310px, calc(100vw - 18px)); padding: 9px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; border: 1px solid var(--border); border-radius: 16px; background: var(--panel-solid); box-shadow: var(--shadow); }
.emoji-item { border: 0; background: transparent; height: 31px; border-radius: 8px; font-size: 18px; cursor: pointer; }
.emoji-item:hover { background: var(--panel-soft); transform: scale(1.12); }

.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(11, 16, 27, .25); backdrop-filter: blur(2px); }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(300px, 84vw); height: 100%; padding: 12px; background: var(--panel-solid); border-left: 1px solid var(--border); box-shadow: -20px 0 45px rgba(20, 30, 55, .13); animation: drawer-in .2s ease-out; }
@keyframes drawer-in { from { transform: translateX(100%); } }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 5px 3px 13px; border-bottom: 1px solid var(--border); }
.drawer-header div { display: grid; gap: 2px; }
.drawer-header strong { font-size: 14px; }.drawer-header span { color: var(--muted); font-size: 10.5px; }
.member-list { padding-top: 10px; overflow-y: auto; max-height: calc(100% - 62px); }
.member-item { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 12px; }
.member-item:hover { background: var(--panel-soft); }
.member-avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: white; font-weight: 700; }
.member-copy { min-width: 0; flex: 1; display: grid; gap: 2px; }
.member-copy strong, .member-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-copy strong { font-size: 12.5px; }.member-copy span { color: var(--muted); font-size: 10.5px; }
.member-tabs { color: var(--subtle); font-size: 10px; }

.settings-dialog { width: min(355px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--border); border-radius: 20px; color: var(--text); background: var(--panel-solid); box-shadow: var(--shadow); }
.settings-dialog::backdrop { background: rgba(11, 16, 27, .35); backdrop-filter: blur(3px); }
.settings-card { padding: 15px; }
.settings-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.settings-header div { display: grid; gap: 3px; }.settings-header strong { font-size: 15px; }.settings-header span { color: var(--muted); font-size: 10.5px; }
.field-label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 11px; font-weight: 650; }
.text-input { width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 12px; outline: 0; padding: 0 11px; color: var(--text); background: var(--panel-soft); }
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.color-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; }
.color-option { aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }
.color-option.selected { outline: 2px solid var(--panel-solid); box-shadow: 0 0 0 3px currentColor; }
.preview-profile { margin-top: 16px; padding: 10px; display: flex; align-items: center; gap: 10px; background: var(--panel-soft); border-radius: 13px; }
.preview-avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: white; font-weight: 750; }
.preview-profile div { display: grid; gap: 2px; }.preview-profile span:last-child { color: var(--muted); font-size: 10px; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.secondary-button, .primary-button { min-width: 72px; height: 36px; border-radius: 11px; cursor: pointer; }
.secondary-button { border: 1px solid var(--border); color: var(--muted); background: var(--panel-soft); }
.primary-button { border: 0; color: white; background: var(--accent); }

.toast-region { position: fixed; top: 76px; left: 50%; z-index: 80; transform: translateX(-50%); display: grid; gap: 6px; width: min(310px, calc(100vw - 24px)); pointer-events: none; }
.toast { padding: 9px 11px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-solid); box-shadow: var(--shadow); color: var(--text); font-size: 11.5px; animation: toast-in .2s ease-out; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-5px); } }

@media (max-width: 360px) {
  .topbar { padding-left: 11px; padding-right: 9px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 11px; }
  .brand-copy strong { font-size: 13px; }
  .top-actions { gap: 0; }
  .icon-button { width: 31px; }
  .online-button { min-width: 37px; padding: 0 4px; }
  .message-body { max-width: 85%; }
  .emoji-panel { grid-template-columns: repeat(7, 1fr); }
}

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

.bot-check { position: fixed; inset: 0; z-index: 75; display: grid; place-items: center; padding: 20px; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(8px); }
.bot-check[hidden] { display: none; }
.bot-check-card { width: min(340px, calc(100vw - 30px)); padding: 22px 18px; display: grid; justify-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 20px; background: var(--panel-solid); box-shadow: var(--shadow); text-align: center; }
.bot-check-card strong { font-size: 14px; }
.bot-check-card p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.55; }
.bot-check-spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-right-color: var(--accent); border-radius: 50%; animation: bot-check-spin .8s linear infinite; }
.turnstile-container { min-width: 300px; min-height: 65px; margin-top: 4px; display: grid; place-items: center; }
.turnstile-container[hidden] { display: none; }
@keyframes bot-check-spin { to { transform: rotate(360deg); } }
