:root {
  --bg: #050505;
  --panel: #101010;
  --panel-2: #161616;
  --panel-3: #1d1d1d;
  --line: #292929;
  --text: #f8f8f8;
  --muted: #a5a5a5;
  --soft: #d9d9d9;
  --accent: #ffffff;
  --accent-text: #050505;
  --danger: #ff6767;
  --ok: #64f09d;
  --cyan: #8fd7ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.48);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: linear-gradient(135deg, #030303, var(--bg) 48%, #101010);
  color: var(--text);
  overflow: hidden;
}
html[data-theme="light"] body { background: linear-gradient(135deg, #f7f7f3, var(--bg) 52%, #e8e8e2); }
html[data-theme="light"] .rail,
html[data-theme="light"] .profile-footer,
html[data-theme="light"] .chat-header,
html[data-theme="light"] .message-form,
html[data-theme="light"] .call-panel,
html[data-theme="light"] .modal,
html[data-theme="light"] .toast,
html[data-theme="light"] .search-results,
html[data-theme="light"] .attach-menu { background: rgba(255,255,255,.92); }
html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] .member-picker,
html[data-theme="light"] .profile-view-head,
html[data-theme="light"] .group-profile-tools { background: #fbfbf8; }
html[data-theme="light"] .message-bubble { background: rgba(255,255,255,.72); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

@keyframes liftIn { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes appEnter { from { opacity: 0; transform: translateY(14px) scale(.985); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes skeletonShine { to { transform: translateX(220%); } }
@keyframes themeWave { from { clip-path: circle(0 at 100% 0); } to { clip-path: circle(150% at 100% 0); } }
@keyframes letterFlip { 0% { transform: translateY(0) rotateX(0); } 45% { transform: translateY(-4px) rotateX(92deg); } 100% { transform: translateY(0) rotateX(0); } }
@keyframes pulseDot { 0%,100% { box-shadow: 0 0 0 0 rgba(100,240,157,.42); } 50% { box-shadow: 0 0 0 6px rgba(100,240,157,0); } }
@keyframes dropGlow { 0%,100% { transform: scale(.99); box-shadow: 0 0 0 1px rgba(143,215,255,.2), 0 18px 55px rgba(0,0,0,.45); } 50% { transform: scale(1); box-shadow: 0 0 0 1px rgba(143,215,255,.55), 0 22px 70px rgba(143,215,255,.12); } }

.auth-shell { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  background: rgba(14, 14, 14, .92);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 22px;
  animation: liftIn .34s ease both;
}
.brand-mark { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.brand-mark img { width: 56px; height: 56px; border-radius: 8px; }
.brand-mark strong { display: block; font-size: 28px; letter-spacing: 0; }
.brand-mark span, .chat-identity span, .profile-copy span, .friend-copy span, .message-meta, .requests-panel p, .modal p, .section-title b { color: var(--muted); font-size: 12px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.auth-tabs button, .control-button, .danger-button, .modal-actions button, .message-form button, .primary-action {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.auth-tabs button:hover, .control-button:hover, .modal-actions button:hover, .message-form button:hover, .primary-action:hover, .icon-button:hover, .rail-icon:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,0,0,.22); }
.auth-tabs button:active, .control-button:active, .modal-actions button:active, .message-form button:active, .primary-action:active, .icon-button:active, .rail-icon:active { transform: translateY(0) scale(.98); }
.auth-tabs button.active, .primary-action, .message-form button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 800; }
.auth-form, .modal form { display: grid; gap: 12px; }
label { display: grid; gap: 7px; color: var(--soft); font-size: 12px; font-weight: 800; }
input, select {
  width: 100%; min-height: 40px; border: 1px solid var(--line); background: #090909; color: var(--text); border-radius: 8px; padding: 0 11px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,255,255,.08); }
.form-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 12px; }
.captcha-row { display: grid; grid-template-columns: 86px minmax(0,1fr) 58px; gap: 7px; align-items: center; }
.captcha-row span { min-height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: radial-gradient(circle at 30% 20%, rgba(143,215,255,.16), transparent 56px), #090909; color: var(--cyan); font-size: 16px; font-weight: 950; }
.captcha-row button { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 11px; font-weight: 900; }
.captcha-row button:hover { border-color: var(--cyan); transform: translateY(-1px); }

.app-shell { height: 100%; display: grid; grid-template-columns: 64px 292px minmax(0, 1fr); background: var(--bg); }
.app-shell.entering { animation: appEnter .5s cubic-bezier(.2,.8,.2,1) both; }
.rail { border-right: 1px solid var(--line); background: #030303; padding: 10px 8px; display: flex; flex-direction: column; gap: 9px; align-items: center; }
.rail-logo { width: 42px; height: 42px; border-radius: 8px; margin-bottom: 4px; }
.rail-icon, .icon-button, .tiny-button {
  display: grid; place-items: center; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; transition: .16s ease;
}
.rail-icon { width: 46px; height: 42px; font-size: 12px; font-weight: 900; }
.home-rail-button img { width: 27px; height: 27px; object-fit: contain; filter: drop-shadow(0 0 8px rgba(255,255,255,.18)); }
.rail-icon.active, .icon-button:hover, .tiny-button:hover, .friend-item.active { border-color: var(--accent); background: var(--panel-2); }
.sidebar { min-width: 0; border-right: 1px solid var(--line); background: rgba(13,13,13,.98); display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.sidebar-view { min-height: 0; display: none; grid-template-rows: auto minmax(0, 1fr); }
.sidebar-view.active { display: grid; animation: liftIn .18s ease both; }
.social-scroll { display: grid; align-content: start; gap: 2px; }
.sidebar-header, .chat-header { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.sidebar-header span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-header strong { display: block; font-size: 18px; }
.header-actions { display: flex; gap: 6px; }
.icon-button { width: 38px; height: 36px; flex: 0 0 auto; font-size: 11px; font-weight: 900; }
.icon-button.subtle { opacity: .72; }
.search-box { position: relative; padding: 10px 10px 8px; }
.search-box input { min-height: 36px; background: #080808; }
.search-results {
  position: absolute; left: 10px; right: 10px; top: 50px; z-index: 15; max-height: 310px; overflow: auto;
  border: 1px solid var(--line); background: #111; border-radius: 8px; box-shadow: var(--shadow); padding: 6px; animation: liftIn .16s ease both;
}
.search-row { display: grid; grid-template-columns: 34px minmax(0,1fr) auto; align-items: center; gap: 8px; padding: 7px; border-radius: 8px; }
.search-row:hover { background: var(--panel-2); }
.search-row button { min-height: 30px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--accent); color: var(--accent-text); font-weight: 800; }
.requests-panel { display: grid; gap: 7px; padding: 0 10px 8px; }
.muted-panel .request-item { opacity: .76; }
.sidebar-scroll { min-height: 0; overflow: auto; padding: 4px 10px 10px; }
.section-title { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; padding: 10px 3px 6px; }
.friends-list { display: grid; gap: 4px; }
.request-item, .friend-item, .group-member-row {
  width: 100%; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 9px; border: 1px solid transparent; background: transparent; color: var(--text); border-radius: 8px; padding: 7px; text-align: left; animation: slideIn .18s ease both;
}
.friend-item:hover, .request-item:hover { background: var(--panel-2); }
.friend-copy { min-width: 0; }
.friend-copy strong, .friend-copy span, .profile-copy strong, .profile-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.request-actions { display: flex; gap: 5px; }
.request-actions button { height: 30px; min-width: 32px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 7px; }
.presence { width: 9px; height: 9px; border-radius: 99px; background: #555; }
.presence.online { background: var(--ok); animation: pulseDot 1.8s ease infinite; }
.profile-footer { min-height: 68px; display: grid; grid-template-columns: minmax(0,1fr) 38px 38px; gap: 8px; align-items: center; padding: 10px; border-top: 1px solid var(--line); background: #070707; }
.profile-button { min-width: 0; display: grid; grid-template-columns: 40px minmax(0,1fr); align-items: center; gap: 9px; border: 0; background: transparent; color: var(--text); text-align: left; border-radius: 8px; padding: 4px; }
.profile-button:hover { background: var(--panel-2); }
.avatar { width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center; color: #050505; background: var(--accent); font-weight: 950; text-transform: uppercase; overflow: hidden; }
.avatar.big { width: 58px; height: 58px; font-size: 18px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.muted { background: #2a2a2a; color: var(--muted); }
.avatar-badge-wrap { position: relative; display: inline-grid; }
.avatar-badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--ok); color: #050505; font-size: 11px; font-weight: 900; line-height: 1; box-shadow: 0 0 0 2px rgba(0,0,0,.18); }

.chat-shell {
  min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0,1fr) auto;
  background: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px), var(--bg);
  background-size: 28px 28px;
}
.chat-header { min-height: 64px; background: rgba(5,5,5,.78); backdrop-filter: blur(14px); }
.chat-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-identity strong { display: block; font-size: 16px; }
.call-actions { display: flex; gap: 7px; position: relative; }
.split-action { display: flex; position: relative; }
.split-action .icon-button { width: 54px; border-radius: 8px 0 0 8px; }
.tiny-button { width: 24px; height: 36px; border-left: 0; border-radius: 0 8px 8px 0; font-weight: 900; }
.stream-menu { position: absolute; right: 0; top: 42px; z-index: 20; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; box-shadow: var(--shadow); padding: 6px; }
.stream-menu button { display: block; width: 86px; border: 0; background: transparent; color: var(--text); border-radius: 6px; padding: 8px; text-align: left; }
.stream-menu button:hover { background: rgba(255,255,255,.08); }
.call-panel { border-bottom: 1px solid var(--line); background: #070707; padding: 10px; animation: liftIn .2s ease both; }
.video-grid { display: grid; grid-template-columns: minmax(0,1fr) 190px; gap: 8px; height: min(30vh, 280px); }
video { width: 100%; height: 100%; background: #000; border: 1px solid var(--line); border-radius: 8px; object-fit: cover; }
#remoteVideo { object-fit: contain; }
.call-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
#callStatus { color: var(--muted); margin-right: auto; font-size: 12px; }
.danger-button { background: var(--danger); color: #160000; border-color: var(--danger); font-weight: 900; }
.messages { position: relative; min-height: 0; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 9px; }
.messages.drag-ready { outline: 1px solid rgba(143,215,255,.45); outline-offset: -8px; background: linear-gradient(rgba(143,215,255,.035), rgba(143,215,255,.015)); }
.drop-scene { position: absolute; z-index: 18; left: 50%; top: 50%; width: min(380px, calc(100% - 36px)); min-height: 150px; transform: translate(-50%, -50%); display: grid; place-items: center; align-content: center; gap: 7px; border: 1px dashed rgba(143,215,255,.7); border-radius: 8px; background: rgba(8,14,18,.92); color: var(--text); text-align: center; pointer-events: none; backdrop-filter: blur(14px); animation: dropGlow 1.25s ease infinite; }
.drop-scene strong { font-size: 20px; }
.drop-scene span { color: var(--muted); max-width: 260px; font-size: 12px; line-height: 1.45; }
.empty-state { margin: auto; max-width: 520px; text-align: center; color: var(--muted); line-height: 1.5; animation: liftIn .25s ease both; }
.empty-state strong { display: block; color: var(--text); font-size: 28px; margin-bottom: 6px; }
.message { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 9px; max-width: min(780px, 82%); animation: liftIn .16s ease both; transition: transform .15s ease, filter .15s ease; }
.message.new-message { animation: messageArrive .34s cubic-bezier(.2,.8,.2,1) both; }
.message:hover { transform: translateY(-1px); filter: brightness(1.04); }
.skeleton-message { pointer-events: none; }
.skeleton-avatar, .skeleton-bubble { position: relative; overflow: hidden; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08); }
.skeleton-avatar { width: 36px; height: 36px; border-radius: 999px; }
.skeleton-bubble { min-height: 62px; width: min(420px, 76vw); }
.skeleton-bubble span, .skeleton-bubble i { display: block; height: 11px; border-radius: 99px; background: rgba(255,255,255,.13); margin: 9px 0; }
.skeleton-bubble span { width: 64%; }
.skeleton-bubble i { width: 38%; }
.skeleton-avatar::after, .skeleton-bubble::after { content: ""; position: absolute; inset: 0; transform: translateX(-120%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.14), transparent); animation: skeletonShine 1.25s ease infinite; }
.message.mine { align-self: flex-end; grid-template-columns: minmax(0, 1fr); }
.message-bubble { border: 1px solid rgba(255,255,255,.14); background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.035)); border-radius: 22px 22px 22px 8px; padding: 10px 13px; overflow-wrap: anywhere; line-height: 1.42; box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 10px 26px rgba(0,0,0,.18); backdrop-filter: blur(16px); }
.message.mine .message-bubble { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 78%, #8fd7ff)); color: var(--accent-text); border-color: rgba(255,255,255,.34); border-radius: 22px 22px 8px 22px; }
.message.mine .message-meta { color: rgba(0,0,0,.58); }
.message-link { display: inline; color: var(--cyan); font-weight: 850; text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--cyan) 58%, transparent); overflow-wrap: anywhere; }
.message-link:hover { color: var(--text); border-bottom-color: currentColor; }
.message.mine .message-link { color: #053048; border-bottom-color: rgba(5,48,72,.45); }
.link-preview-list { display: grid; gap: 7px; margin-top: 9px; }
.link-preview-card { width: min(430px, 100%); display: grid; grid-template-columns: 38px minmax(0,1fr); align-items: center; gap: 9px; border: 1px solid rgba(143,215,255,.28); border-radius: 8px; background: rgba(143,215,255,.07); color: var(--text); padding: 8px; text-decoration: none; transition: border-color .16s ease, background .16s ease, transform .16s ease; }
.link-preview-card:hover { border-color: var(--cyan); background: rgba(143,215,255,.12); transform: translateY(-1px); }
.message.mine .link-preview-card { background: rgba(255,255,255,.22); border-color: rgba(0,0,0,.22); color: #050505; }
.link-preview-favicon { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.16); border-radius: 8px; background: rgba(0,0,0,.24); overflow: hidden; }
.link-preview-favicon img { width: 22px; height: 22px; object-fit: contain; }
.link-preview-card b, .link-preview-card small, .link-preview-card em { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-preview-card b { font-size: 13px; }
.link-preview-card small { color: var(--muted); font-size: 11px; font-weight: 850; }
.link-preview-card em { color: var(--muted); font-size: 11px; font-style: normal; }
.message.mine .link-preview-card small, .message.mine .link-preview-card em { color: rgba(0,0,0,.58); }
.message-form { position: relative; display: grid; grid-template-columns: 44px 44px minmax(0,1fr) 52px; gap: 8px; padding: 12px; border-top: 1px solid rgba(255,255,255,.12); background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02)), rgba(5,5,5,.78); backdrop-filter: blur(18px); }
.message-form input, .message-form button { min-height: 42px; }
.message-form #messageInput { border-radius: 999px; padding: 0 16px; background: rgba(255,255,255,.075); border-color: rgba(255,255,255,.14); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.tool-button { border: 1px solid rgba(255,255,255,.14); border-radius: 999px; background: rgba(255,255,255,.075); color: var(--text); font-size: 11px; font-weight: 900; box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.attach-wrap { position: relative; display: grid; }
.attach-menu {
  position: absolute;
  left: 0;
  bottom: 52px;
  z-index: 30;
  min-width: 208px;
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 20px;
  background: rgba(16,16,16,.82);
  box-shadow: 0 22px 60px rgba(0,0,0,.44), inset 0 1px 0 rgba(255,255,255,.08);
  backdrop-filter: blur(18px);
  animation: attachBubble .18s cubic-bezier(.2,.8,.2,1) both;
}
.attach-menu button {
  min-height: 40px;
  display: grid;
  grid-template-columns: 22px minmax(0,1fr);
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0 10px;
  font-weight: 850;
}
.attach-menu button:hover { background: rgba(255,255,255,.09); }
@keyframes attachBubble { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.tool-button.recording { background: var(--danger); color: #160000; border-color: var(--danger); animation: pulseDot 1.1s ease infinite; }
.attachment-list { display: grid; gap: 7px; margin-top: 7px; }
.attachment-image { max-width: min(360px, 100%); max-height: 260px; border-radius: 8px; border: 1px solid var(--line); object-fit: contain; background: #050505; }
.attachment-file { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.06); color: inherit; text-decoration: none; font-weight: 800; }
.attachment-audio { width: min(360px, 100%); height: 36px; }
.message-pending { color: var(--muted); font-size: 12px; padding: 0 6px; }
.message-form button:disabled, .message-form input:disabled, .icon-button:disabled, .tiny-button:disabled { opacity: .38; cursor: not-allowed; transform: none; }
#screenButton:disabled, #streamMenuButton:disabled { filter: grayscale(1); }

.modal { width: min(420px, calc(100vw - 28px)); border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; animation: liftIn .18s ease both; }
.wide-modal { width: min(560px, calc(100vw - 28px)); }
.mini-modal { width: min(380px, calc(100vw - 28px)); }
.modal::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.modal h2 { margin: 0; }
.dialog-subtitle { font-size: 13px; color: var(--soft); margin-top: 4px !important; }
.modal p { margin: 0; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.settings-page-form { min-height: 0; overflow: auto; padding: 10px; display: grid; gap: 10px; align-content: start; }
.settings-group { display: grid; gap: 9px; padding: 12px; border: 1px solid rgba(255,255,255,.12); border-radius: 18px; background: rgba(255,255,255,.045); box-shadow: inset 0 1px 0 rgba(255,255,255,.06); }
.settings-group h3 { margin: 0; font-size: 13px; color: var(--soft); }
.custom-theme-controls { display: grid; gap: 9px; }
.theme-preview { min-height: 72px; display: grid; grid-template-columns: 42px minmax(0,1fr); align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--text); background: var(--bg); transition: background .2s ease, color .2s ease; }
.theme-preview span { width: 38px; height: 38px; border-radius: 999px; background: var(--accent); box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); grid-row: span 2; }
.theme-preview b, .theme-preview small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-preview small { color: var(--muted); font-weight: 800; }
.check-row { display: flex; grid-template-columns: none; align-items: center; gap: 9px; }
.check-row input { width: 18px; min-height: 18px; accent-color: var(--accent); }
.poll-options-list { display: grid; gap: 8px; }
.poll-option-row { display: grid; grid-template-columns: minmax(0,1fr) 38px; gap: 8px; align-items: center; }
.poll-option-row button { min-height: 38px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); }
.poll-card { display: grid; gap: 9px; min-width: min(320px, 100%); }
.poll-card strong { display: block; font-size: 15px; }
.poll-choice { min-height: 40px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; border: 1px solid rgba(255,255,255,.14); border-radius: 999px; background: rgba(255,255,255,.06); color: inherit; padding: 0 12px; text-align: left; }
.poll-choice:hover { border-color: var(--accent); transform: translateY(-1px); }
.poll-choice.voted { background: rgba(100,240,157,.12); border-color: rgba(100,240,157,.5); }
.poll-check { color: var(--ok); font-weight: 950; }
.member-picker { display: grid; gap: 5px; max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: #080808; }
.compact-picker { max-height: 180px; }
.compact-empty { padding: 10px; font-size: 12px; }
.group-profile-tools { display: grid; grid-template-columns: 48px minmax(0,1fr); align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #080808; }
.group-profile-tools .avatar { width: 44px; height: 44px; }
.group-profile-tools input { min-height: 36px; padding: 7px; }
.group-member-row { grid-template-columns: 34px minmax(0,1fr) auto; padding: 6px; }
.group-member-row input { width: 18px; min-height: 18px; }
.member-actions { display: flex; align-items: center; justify-content: flex-end; gap: 5px; min-width: 22px; }
.member-actions button { min-height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--text); font-size: 11px; font-weight: 900; }
.member-actions .danger-button { background: rgba(255,103,103,.16); border-color: rgba(255,103,103,.55); color: var(--danger); }
.profile-editor-preview { display: flex; align-items: center; gap: 12px; padding: 10px; background: #080808; border: 1px solid var(--line); border-radius: 8px; }
.profile-editor-preview span { display: block; color: var(--muted); font-size: 12px; }
.update-overlay { position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center; gap: 8px; align-content: center; background: rgba(0,0,0,.9); color: var(--text); text-align: center; }
.update-overlay strong { font-size: 28px; }
.update-overlay span { color: var(--muted); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 80; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: #111; color: var(--text); box-shadow: var(--shadow); animation: liftIn .16s ease both; }
.theme-wave { position: fixed; inset: 0; z-index: 9000; pointer-events: none; animation: themeWave .72s cubic-bezier(.2,.8,.2,1) both; }
.language-flip main, .language-flip dialog[open], .language-flip .toast { animation: letterFlip .62s ease both; transform-origin: center; }
.message-action-overlay { position: fixed; inset: 0; z-index: 8500; display: grid; place-items: center; padding: 18px; background: rgba(0,0,0,.28); backdrop-filter: blur(0); opacity: 0; transition: opacity .18s ease, backdrop-filter .18s ease; }
.message-action-overlay.visible { opacity: 1; backdrop-filter: blur(14px); }
.message-action-card { position: relative; width: min(560px, 100%); display: grid; gap: 12px; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; background: rgba(16,16,16,.92); color: var(--text); box-shadow: var(--shadow); padding: 14px; animation: liftIn .2s cubic-bezier(.2,.8,.2,1) both; }
.message-action-preview { display: grid; grid-template-columns: 36px minmax(0,1fr); gap: 9px; align-items: start; max-height: 36vh; overflow: auto; padding-top: 30px; }
.message-action-preview > .message-bubble:first-child { grid-column: 1 / -1; }
.message-action-close { position: absolute; right: 12px; top: 12px; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); font-weight: 950; }
.message-action-card textarea { margin-top: 6px; }
.call-join-banner { margin-left: 8px; min-height: 36px; display: inline-grid; grid-template-columns: 18px minmax(0,1fr) auto; align-items: center; gap: 8px; max-width: min(280px, 38vw); border: 1px solid rgba(100,240,157,.55); border-radius: 8px; background: rgba(100,240,157,.12); color: var(--text); padding: 0 10px; animation: liftIn .18s ease both; }
.call-join-banner b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.call-join-banner em { min-height: 24px; display: grid; place-items: center; padding: 0 8px; border-radius: 7px; background: var(--ok); color: #052112; font-style: normal; font-weight: 950; font-size: 11px; }
.call-join-banner [data-icon] { width: 18px; height: 18px; color: var(--ok); }

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { min-height: 100%; height: auto; grid-template-columns: 56px minmax(0,1fr); }
  .rail, .sidebar { min-height: 100vh; }
  .chat-shell { grid-column: 1 / -1; min-height: 82vh; }
  .video-grid { grid-template-columns: 1fr; height: auto; }
  video { aspect-ratio: 16 / 9; }
}
@media (max-width: 560px) {
  .message-form { grid-template-columns: 40px 40px minmax(0,1fr) 46px; }
  html, body { height: 100%; overflow: hidden; }
  body { overflow: hidden; }
  .app-shell {
    --mobile-rail: 48px;
    --mobile-sidebar: calc(100vw - 70px);
    width: calc(var(--mobile-rail) + var(--mobile-sidebar) + 100vw);
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: var(--mobile-rail) var(--mobile-sidebar) 100vw;
    transform: translateX(0);
    transition: transform .24s ease;
    overflow: hidden;
    touch-action: pan-y;
    will-change: transform;
  }
  .app-shell.chat-open { transform: translateX(calc(-1 * (var(--mobile-rail) + var(--mobile-sidebar)))); }
  .rail {
    display: flex;
    min-height: 100dvh;
    height: 100dvh;
    padding: calc(8px + env(safe-area-inset-top)) 4px calc(8px + env(safe-area-inset-bottom));
    overflow: hidden;
  }
  .rail-logo { display: none; }
  .rail-icon { width: 38px; height: 38px; }
  .home-rail-button img { width: 24px; height: 24px; }
  .sidebar {
    position: relative;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }
  .sidebar-header {
    min-height: calc(66px + env(safe-area-inset-top));
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .search-results { max-height: min(310px, calc(100dvh - 170px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
  .sidebar-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .profile-footer {
    position: absolute;
    z-index: 12;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: calc(72px + env(safe-area-inset-bottom));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255,255,255,.16);
    background: rgba(7,7,7,.96);
    box-shadow: 0 -16px 38px rgba(0,0,0,.42);
    backdrop-filter: blur(14px);
  }
  .chat-shell {
    grid-column: auto;
    min-height: 100dvh;
    height: 100dvh;
    box-shadow: -16px 0 32px rgba(0,0,0,.38);
  }
  .chat-header {
    min-height: calc(64px + env(safe-area-inset-top));
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .messages { overscroll-behavior: contain; }
  .message { max-width: 96%; }
  .message-form { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .chat-header { align-items: flex-start; flex-direction: column; }
  .modal {
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
  }
}

.call-panel.hidden {
  display: block !important;
  height: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  background: radial-gradient(circle at 50% 40%, rgba(255,255,255,.12), transparent 260px), #050505;
  color: #fff;
  transition: opacity .35s ease, transform .35s ease, visibility .35s ease;
}
.boot-screen.done {
  opacity: 0;
  transform: scale(1.02);
  visibility: hidden;
}
.boot-logo {
  position: relative;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
}
.boot-logo img {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  animation: bootFloat 1.45s ease infinite;
}
.boot-logo span {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255,255,255,.34);
  border-top-color: #fff;
  border-radius: 999px;
  animation: bootSpin 1s linear infinite;
}
.boot-screen strong { font-size: 34px; }
.boot-screen p { margin: 0; color: var(--muted); }
@keyframes bootSpin { to { transform: rotate(360deg); } }
@keyframes bootFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes messageArrive {
  0% { opacity: 0; transform: translateY(12px) scale(.985); filter: brightness(1.12); }
  65% { opacity: 1; transform: translateY(-1px) scale(1.005); filter: brightness(1.08); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: brightness(1); }
}

.boot-screen.done {
  pointer-events: none;
}
.app-loading-overlay { position: fixed; inset: 0; z-index: 11000; display: grid; place-items: center; align-content: center; gap: 12px; background: rgba(0,0,0,.86); color: var(--text); opacity: 1; transition: opacity .24s ease, visibility .24s ease; }
.app-loading-overlay.done { opacity: 0; visibility: hidden; }
.app-loading-overlay strong { font-size: 15px; }
.app-loading-spinner { width: 46px; height: 46px; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--accent); border-radius: 999px; animation: bootSpin .75s linear infinite; }
.selection-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); background: #090909; }
.selection-bar strong { margin-right: auto; font-size: 12px; color: var(--soft); }
.selection-bar button { min-height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); padding: 0 10px; font-weight: 800; }
.message.selected .message-bubble { outline: 2px solid var(--cyan); outline-offset: 2px; }
.message.deleted .message-bubble { opacity: .72; font-style: italic; }
.pending-attachments { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; border-top: 1px solid var(--line); background: rgba(8,8,8,.94); }
.pending-card { position: relative; width: 74px; height: 74px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 11px; text-align: center; padding: 4px; }
.pending-card img, .pending-card video { width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 0; }
.pending-card button { position: absolute; right: 3px; top: 3px; width: 22px; height: 22px; border-radius: 7px; border: 1px solid var(--line); background: rgba(0,0,0,.72); color: #fff; }
.attachment-video { width: min(360px,100%); max-height: 260px; border-radius: 8px; border: 1px solid var(--line); background: #000; }
.profile-view { display: grid; gap: 12px; }
.profile-view-head { display: flex; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #080808; }
.member-picker .group-member-row { cursor: pointer; }
@media (max-width: 560px) { .selection-bar { align-items: stretch; } .selection-bar strong { width: 100%; } .selection-bar button { flex: 1 1 46%; } .pending-card { width: 62px; height: 62px; } }

.call-participants { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.call-chip { min-height: 28px; display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--soft); font-size: 12px; font-weight: 800; }
.call-chip.connected { color: var(--ok); border-color: rgba(100,240,157,.42); }
.call-chip::before { content: ''; width: 7px; height: 7px; border-radius: 99px; background: currentColor; }
.incoming-card { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #080808; }
.incoming-card strong, .incoming-card span { display: block; }
.incoming-card span { color: var(--muted); font-size: 12px; }

.verified-badge { display: inline-grid; width: 16px; height: 16px; margin-left: 5px; vertical-align: -3px; background: url('/icons/verified-badge.png') center / contain no-repeat; filter: drop-shadow(0 0 5px rgba(255,255,255,.18)); }
.message.call-message { max-width: min(560px, 82%); }
.call-message-card { display: flex; align-items: center; gap: 10px; color: var(--danger); }
.call-message-card strong, .call-message-card small { display: block; }
.call-message-card small { color: var(--muted); font-size: 12px; }
.call-x { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 999px; background: rgba(255,103,103,.13); border: 1px solid rgba(255,103,103,.48); color: var(--danger); font-weight: 950; }
.moderation-overlay { position: fixed; inset: 0; z-index: 9998; display: grid; place-items: center; padding: 18px; background: radial-gradient(circle at 50% 20%, rgba(255,103,103,.12), transparent 260px), rgba(0,0,0,.94); color: var(--text); }
.moderation-card { width: min(560px, 100%); border: 1px solid rgba(255,103,103,.4); border-radius: 8px; background: #0d0d0d; box-shadow: var(--shadow); padding: 20px; display: grid; gap: 12px; animation: liftIn .2s ease both; }
.moderation-card b { color: var(--danger); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.moderation-card h1 { margin: 0; font-size: clamp(26px, 5vw, 44px); letter-spacing: 0; }
.moderation-card p { margin: 0; color: var(--soft); line-height: 1.5; }
.moderation-note, .moderation-until { border: 1px solid var(--line); border-radius: 8px; background: #070707; padding: 10px; color: var(--muted); line-height: 1.5; }
.moderation-card .primary-action:disabled { opacity: .45; cursor: not-allowed; }
.moderation-menu-wrap { position: fixed; right: 14px; top: 14px; z-index: 10000; }
.moderation-menu { position: absolute; right: 0; top: 42px; min-width: 140px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px; box-shadow: var(--shadow); }
.moderation-menu button { width: 100%; min-height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; padding: 0 10px; font-weight: 800; }
.moderation-menu button:hover { background: var(--panel-2); }
.profile-admin-actions { flex-wrap: wrap; }
.profile-admin-actions button { flex: 0 0 auto; }

textarea { width: 100%; min-height: 92px; resize: vertical; border: 1px solid var(--line); background: #090909; color: var(--text); border-radius: 8px; padding: 10px 11px; outline: none; font: inherit; }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,255,255,.08); }

.stream-watch-wrap { position: relative; min-height: 0; }
.stream-watch-wrap .primary-action { position: absolute; z-index: 4; left: 50%; top: 12px; transform: translateX(-50%); min-height: 34px; }
#remoteVideo.stream-locked { filter: brightness(.18) blur(1px); cursor: pointer; }
.stream-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stream-tabs label { min-height: 42px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: #090909; }
.stream-tabs input { width: 18px; min-height: 18px; }
.modal-hint { color: var(--muted); font-size: 12px; }

.link-button { min-height: 30px; border: 0; background: transparent; color: var(--muted); text-align: left; padding: 0; font-weight: 800; }
.link-button:hover { color: var(--text); }
.code-inputs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.code-inputs input { text-align: center; font-size: 22px; font-weight: 900; }

.password-row { display: grid; grid-template-columns: minmax(0,1fr) 58px; gap: 7px; }
.password-row input { min-width: 0; }
.password-row button { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); font-weight: 900; font-size: 11px; }

/* CatMat 0.1.17 call and stream polish */
.side-icons { display: inline-flex; align-items: center; gap: 7px; }
.friend-item.in-call { border-color: rgba(100,240,157,.45); background: rgba(100,240,157,.055); }
.chat-call-icon { min-width: 28px; height: 22px; display: grid; place-items: center; border: 1px solid rgba(100,240,157,.5); border-radius: 7px; color: var(--ok); font-size: 10px; font-weight: 950; letter-spacing: 0; background: rgba(100,240,157,.08); animation: callBlink 1.6s ease infinite; }
.avatar { border: 1px solid rgba(255,255,255,.22); box-shadow: inset 0 0 0 1px rgba(0,0,0,.22); }
.boot-screen { background: radial-gradient(circle at 50% 38%, rgba(255,255,255,.14), transparent 240px), linear-gradient(180deg,#050505,#000); }
.boot-logo { width: 104px; height: 104px; }
.boot-logo img { width: 86px; height: 86px; border-radius: 0; object-fit: contain; filter: drop-shadow(0 0 24px rgba(255,255,255,.22)); }
.boot-screen p { color: #fff; font-weight: 900; letter-spacing: 0; }
.boot-screen small { color: var(--muted); font-weight: 800; }
.call-panel { padding: 12px; background: linear-gradient(180deg, rgba(255,255,255,.035), transparent), #050505; }
.call-stage { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: stretch; }
.call-panel.has-stream .call-stage { grid-template-columns: minmax(220px,.72fr) minmax(320px,1.28fr); }
.call-participants { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); gap: 8px; }
.call-card { min-height: 118px; display: grid; align-content: center; justify-items: center; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: radial-gradient(circle at 50% 0%, rgba(255,255,255,.09), transparent 76px), var(--panel-2); color: var(--text); transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease; }
.call-card .avatar { width: 48px; height: 48px; border-radius: 14px; border: 2px solid rgba(255,255,255,.32); }
.call-card strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.call-card span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; font-weight: 800; }
.call-card.connected { border-color: rgba(255,255,255,.34); }
.call-card.speaking { border-color: var(--ok); box-shadow: 0 0 0 2px rgba(100,240,157,.18), 0 0 28px rgba(100,240,157,.18); transform: translateY(-1px); }
.video-grid { min-height: 220px; border: 1px solid var(--line); border-radius: 8px; background: #020202; padding: 8px; }
.video-grid video { min-height: 0; }
.stream-watch-wrap { display: none; grid-column: 2; grid-row: 1; pointer-events: none; }
.call-panel.has-stream .stream-watch-wrap { display: block; }
.stream-watch-wrap .primary-action { pointer-events: auto; top: 50%; transform: translate(-50%, -50%); box-shadow: var(--shadow); }
.stream-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stream-tab { min-height: 42px; border: 1px solid var(--line); border-radius: 8px; background: #090909; color: var(--text); font-weight: 900; transition: border-color .14s ease, background .14s ease, transform .14s ease; }
.stream-tab:hover { border-color: rgba(255,255,255,.35); transform: translateY(-1px); }
.stream-tab.active { border-color: var(--accent); background: var(--panel-2); }
.stream-source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; max-height: min(46vh, 430px); overflow: auto; padding: 2px; }
.stream-source-card { min-height: 126px; display: grid; grid-template-rows: minmax(80px,1fr) auto; gap: 7px; border: 1px solid var(--line); border-radius: 8px; background: #070707; color: var(--text); padding: 7px; text-align: left; transition: border-color .14s ease, background .14s ease, transform .14s ease; }
.stream-source-card:hover { border-color: var(--accent); background: var(--panel-2); transform: translateY(-2px); }
.stream-source-card img { width: 100%; height: 96px; border-radius: 6px; object-fit: cover; background: #000; }
.stream-source-card strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.source-fallback-icon, .stream-source-empty { display: grid; place-items: center; min-height: 96px; border: 1px dashed rgba(255,255,255,.22); border-radius: 6px; color: var(--muted); font-size: 12px; font-weight: 900; }
.stream-source-empty { grid-column: 1 / -1; }
@keyframes callBlink { 0%,100% { opacity: .78; } 50% { opacity: 1; box-shadow: 0 0 18px rgba(100,240,157,.22); } }
@media (max-width: 820px) {
  .call-stage { grid-template-columns: 1fr; }
  .stream-watch-wrap { grid-column: 1; }
  .video-grid { min-height: 190px; }
  .call-participants { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  .call-card { min-height: 104px; }
  .stream-source-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}
.call-stage .video-grid { display: none; grid-column: 2; grid-row: 1; }
.call-panel.has-stream .video-grid { display: grid; }
@media (max-width: 820px) { .call-stage .video-grid { grid-column: 1; grid-row: auto; } .stream-watch-wrap { grid-row: auto; } }
@media (max-width: 820px) { .call-stage .video-grid { grid-column: 1; grid-row: 2; } .stream-watch-wrap { grid-column: 1; grid-row: 2; } }

/* CatMat 0.1.18 instant cache and media polish */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.32) rgba(255,255,255,.05); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: rgba(255,255,255,.035); border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,.18)); border: 2px solid rgba(0,0,0,.35); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.58); }
.media-thumb { max-width: min(420px,100%); border: 0; background: transparent; color: inherit; padding: 0; cursor: zoom-in; display: inline-grid; position: relative; border-radius: 8px; overflow: hidden; text-align: left; }
.media-thumb:hover .attachment-image, .media-thumb:hover .attachment-video { border-color: var(--accent); filter: brightness(1.08); transform: scale(1.01); }
.attachment-image, .attachment-video { transition: transform .18s ease, filter .18s ease, border-color .18s ease; }
.video-thumb { background: #000; }
.media-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 56px; height: 34px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.42); border-radius: 8px; background: rgba(0,0,0,.68); color: #fff; font-size: 11px; font-weight: 950; backdrop-filter: blur(10px); }
.media-viewer { position: fixed; inset: 0; z-index: 12000; display: grid; grid-template-rows: minmax(0,1fr) auto; place-items: center; padding: 20px; background: rgba(0,0,0,.9); backdrop-filter: blur(16px); animation: mediaFade .16s ease both; }
.media-viewer-stage { width: min(1180px, 100%); height: min(78vh, 760px); display: grid; place-items: center; }
.media-viewer-stage img, .media-viewer-stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; background: #000; box-shadow: 0 24px 90px rgba(0,0,0,.62); object-fit: contain; }
.media-close { position: fixed; right: 18px; top: 18px; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.24); border-radius: 8px; background: rgba(20,20,20,.86); color: #fff; font-weight: 950; z-index: 1; }
.media-viewer-name { max-width: min(860px,100%); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; font-weight: 800; }
.voice-player { width: min(430px, 100%); display: grid; grid-template-columns: 52px minmax(90px,1fr) minmax(72px,104px) auto; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.015)); }
.voice-play { height: 34px; border: 1px solid rgba(255,255,255,.24); border-radius: 8px; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 950; }
.voice-wave { height: 34px; display: flex; align-items: center; gap: 3px; overflow: hidden; }
.voice-wave span { width: 3px; height: calc(7px + (var(--i) % 7) * 3px); border-radius: 99px; background: rgba(255,255,255,.42); transform-origin: center; animation: voiceIdle 1.8s ease-in-out infinite; animation-delay: calc(var(--i) * -62ms); }
.voice-player.playing .voice-wave span { background: var(--ok); animation-name: voicePlaying; }
.voice-range { width: 100%; accent-color: var(--accent); }
.voice-time { color: var(--muted); font-size: 11px; font-weight: 900; white-space: nowrap; }
.voice-download { display: none; }
@keyframes mediaFade { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: scale(1); } }
@keyframes voiceIdle { 0%,100% { opacity: .45; transform: scaleY(.72); } 50% { opacity: .9; transform: scaleY(1); } }
@keyframes voicePlaying { 0%,100% { transform: scaleY(.55); } 50% { transform: scaleY(1.35); } }
@media (max-width: 560px) {
  .voice-player { grid-template-columns: 48px minmax(0,1fr); }
  .voice-range, .voice-time { grid-column: 1 / -1; }
  .media-viewer { padding: 10px; }
}

/* CatMat 0.1.19 mobile call/stream polish */
.icon-button[data-icon], .tool-button[data-icon], .tiny-button[data-icon], #messageSend[data-icon], .rail-icon[data-icon] { font-size: 0; position: relative; display: inline-grid; place-items: center; }
.icon-button[data-icon]::before, .tool-button[data-icon]::before, .tiny-button[data-icon]::before, #messageSend[data-icon]::before, .rail-icon[data-icon]::before, .attach-menu [data-icon]::before { font-size: 17px; line-height: 1; font-weight: 950; color: currentColor; }
[data-icon]::before { content: ""; width: 18px; height: 18px; background: currentColor; -webkit-mask: var(--icon-mask) center / contain no-repeat; mask: var(--icon-mask) center / contain no-repeat; }
[data-icon="members"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8Zm10 0a4 4 0 1 1 0-8 4 4 0 0 1 0 8ZM2 21v-2a5 5 0 0 1 5-5h1a5 5 0 0 1 5 5v2H2Zm11 0v-2a7 7 0 0 0-2-5h5a6 6 0 0 1 6 6v1h-9Z'/%3E%3C/svg%3E"); }
[data-icon="call"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.6 2.5 10 6 8 9c1.1 2.2 2.8 3.9 5 5l3-2 3.5 3.4c.5.5.6 1.2.3 1.8l-1.4 3c-.3.6-.9.9-1.6.8C9.3 20.3 3.7 14.7 3 7.2c-.1-.7.2-1.3.8-1.6l3-1.4c.6-.3 1.3-.2 1.8.3Z'/%3E%3C/svg%3E"); }
[data-icon="share"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 5h16v10H4V5Zm2 2v6h12V7H6Zm4 10h4v2h5v2H5v-2h5v-2Z'/%3E%3C/svg%3E"); }
[data-icon="chevron"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6H6Z'/%3E%3C/svg%3E"); }
[data-icon="attach"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6V5Z'/%3E%3C/svg%3E"); }
[data-icon="chats"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h16v11H8l-4 4V4Zm3 4v2h10V8H7Zm0 4v2h7v-2H7Z'/%3E%3C/svg%3E"); }
[data-icon="social"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8Zm8.5 1a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7ZM2 21v-2a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v2H2Zm14.5 0v-2a8 8 0 0 0-1.2-4.2A5 5 0 0 1 22 19v2h-5.5Z'/%3E%3C/svg%3E"); }
[data-icon="person-add"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8ZM2 21v-2a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v2H2Zm16-11V7h-3V5h3V2h2v3h3v2h-3v3h-2Z'/%3E%3C/svg%3E"); }
[data-icon="group-add"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 11a4 4 0 1 1 0-8 4 4 0 0 1 0 8Zm10 0a4 4 0 1 1 0-8 4 4 0 0 1 0 8ZM2 21v-2a5 5 0 0 1 5-5h1a5 5 0 0 1 5 5v2H2Zm11 0v-2a7 7 0 0 0-2-5h4v-3h2v3h3v2h-3v3h-2v-3h-2.1c.1.7.1 1.3.1 2v3Z'/%3E%3C/svg%3E"); }
[data-icon="file"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 2h8l5 5v15H6V2Zm7 1.8V8h4.2L13 3.8ZM8 12v2h8v-2H8Zm0 4v2h6v-2H8Z'/%3E%3C/svg%3E"); }
[data-icon="image"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h16v16H4V4Zm2 2v10.5l4.2-4.2 3.2 3.2 2.1-2.1L18 15.9V6H6Zm3.5 5a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z'/%3E%3C/svg%3E"); }
[data-icon="poll"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 21V9h4v12H5Zm5 0V3h4v18h-4Zm5 0V12h4v9h-4Z'/%3E%3C/svg%3E"); }
[data-icon="record"] { color: var(--danger); --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a4 4 0 0 0-4 4v5a4 4 0 0 0 8 0V7a4 4 0 0 0-4-4Zm-6 8h2v1a4 4 0 0 0 8 0v-1h2v1a6 6 0 0 1-5 5.92V21h-2v-3.08A6 6 0 0 1 6 12v-1Z'/%3E%3C/svg%3E"); }
[data-icon="send"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4 22 12 3 20l2-7 10-1-10-1-2-7Z'/%3E%3C/svg%3E"); }
.remote-frame-stream { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #000; z-index: 2; cursor: zoom-in; transition: filter .18s ease, transform .18s ease; }
.remote-frame-stream.stream-locked { filter: brightness(.2) blur(1px); }
.video-grid { position: relative; }
.call-ok { background: rgba(100,240,157,.13); border-color: rgba(100,240,157,.48); color: var(--ok); }
.call-off { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.22); color: var(--soft); }

/* CatMat 0.1.21 incoming call ring */
.ringing-card { position: relative; overflow: hidden; background: radial-gradient(circle at 20% 50%, rgba(255,255,255,.12), transparent 120px), #080808; }
.ringing-card::before { content: ""; position: absolute; inset: -40%; background: conic-gradient(from 0deg, transparent, rgba(100,240,157,.2), transparent, rgba(255,255,255,.14), transparent); animation: ringSweep 2.4s linear infinite; opacity: .75; }
.ringing-card > * { position: relative; z-index: 1; }
.ring-avatar { position: relative; display: grid; place-items: center; }
.ring-avatar .avatar { position: relative; z-index: 3; border-color: rgba(100,240,157,.78); box-shadow: 0 0 0 2px rgba(100,240,157,.18); }
.ring-avatar span, .ring-avatar i { position: absolute; inset: -8px; border: 1px solid rgba(100,240,157,.55); border-radius: 14px; animation: ringPulse 1.45s ease-out infinite; }
.ring-avatar i { inset: -15px; animation-delay: .34s; opacity: .65; }
#incomingCallDialog[open] { animation: incomingPop .18s ease both; }
#incomingCallDialog[open]::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(10px); }
@keyframes ringPulse { 0% { transform: scale(.74); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes ringSweep { to { transform: rotate(360deg); } }
@keyframes incomingPop { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }

.chat-shell.stream-focus { grid-template-rows: auto minmax(0, min(68vh, 720px)) minmax(120px,1fr) auto; }
.chat-shell.stream-focus .call-panel { min-height: 0; height: auto; display: grid; grid-template-rows: minmax(0,1fr) auto; padding: 10px; }
.chat-shell.stream-focus .call-stage { min-height: 0; grid-template-columns: minmax(128px, .22fr) minmax(0, 1fr); }
.chat-shell.stream-focus .video-grid { height: min(62vh, calc(100vh - 190px)); grid-template-columns: minmax(0,1fr) 148px; }
.chat-shell.stream-focus #messages { min-height: 120px; padding: 10px 14px; overflow: auto; }
.chat-shell.stream-focus #remoteVideo, .chat-shell.stream-focus .remote-frame-stream { object-fit: contain; }
[data-icon="settings"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.4 13.5c.1-.5.1-1 .1-1.5s0-1-.1-1.5l2-1.5-2-3.5-2.4 1a7.8 7.8 0 0 0-2.6-1.5L14 2h-4l-.4 3a7.8 7.8 0 0 0-2.6 1.5l-2.4-1-2 3.5 2 1.5c-.1.5-.1 1-.1 1.5s0 1 .1 1.5l-2 1.5 2 3.5 2.4-1a7.8 7.8 0 0 0 2.6 1.5l.4 3h4l.4-3a7.8 7.8 0 0 0 2.6-1.5l2.4 1 2-3.5-2-1.5ZM12 15.5A3.5 3.5 0 1 1 12 8a3.5 3.5 0 0 1 0 7.5Z'/%3E%3C/svg%3E"); }
[data-icon="logout"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 3h9v2H6v14h7v2H4V3Zm11.5 4.5L20 12l-4.5 4.5-1.4-1.4 2.1-2.1H10v-2h6.2l-2.1-2.1 1.4-1.4Z'/%3E%3C/svg%3E"); }
@media (max-width: 820px) { .chat-shell.stream-focus .call-stage { grid-template-columns: 1fr; } .chat-shell.stream-focus .video-grid { height: 62vh; grid-template-columns: 1fr; } }

/* ========================================================================== 
   CatMat Design Refresh 2026-07
   Final override layer: aurora glass, calmer motion and accessible states.
   Keep this section last so legacy release polish above remains compatible.
   ========================================================================== */

/* Design tokens ---------------------------------------------------------- */
:root {
  --cm-rail-width: 72px;
  --cm-sidebar-width: clamp(288px, 24vw, 360px);
  --cm-control-size: 44px;
  --cm-radius-xs: 10px;
  --cm-radius-sm: 14px;
  --cm-radius-md: 18px;
  --cm-radius-lg: 24px;
  --cm-radius-xl: 30px;
  --cm-radius-pill: 999px;
  --cm-motion-fast: 120ms;
  --cm-motion-ui: 210ms;
  --cm-motion-scene: 440ms;
  --cm-ease-standard: cubic-bezier(.2, .72, .2, 1);
  --cm-ease-spring: cubic-bezier(.2, .92, .24, 1.16);
  --cm-surface: color-mix(in srgb, var(--panel) 92%, transparent);
  --cm-surface-soft: color-mix(in srgb, var(--panel-2) 84%, transparent);
  --cm-surface-raised: color-mix(in srgb, var(--panel-2) 94%, var(--bg));
  --cm-surface-hover: color-mix(in srgb, var(--panel-3) 78%, var(--accent) 5%);
  --cm-glass: color-mix(in srgb, var(--panel) 78%, transparent);
  --cm-glass-strong: color-mix(in srgb, var(--panel) 90%, transparent);
  --cm-line-soft: color-mix(in srgb, var(--line) 72%, transparent);
  --cm-line-strong: color-mix(in srgb, var(--text) 22%, var(--line));
  --cm-accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --cm-accent-medium: color-mix(in srgb, var(--accent) 28%, transparent);
  --cm-danger-soft: color-mix(in srgb, var(--danger) 15%, transparent);
  --cm-ok-soft: color-mix(in srgb, var(--ok) 14%, transparent);
  --cm-aurora-a: color-mix(in srgb, var(--accent) 18%, transparent);
  --cm-aurora-b: color-mix(in srgb, var(--cyan) 12%, transparent);
  --cm-aurora-c: color-mix(in srgb, var(--ok) 8%, transparent);
  --cm-shadow-sm: 0 8px 24px rgba(0, 0, 0, .18);
  --cm-shadow-md: 0 18px 52px rgba(0, 0, 0, .28);
  --cm-shadow-lg: 0 32px 100px rgba(0, 0, 0, .46);
  --cm-ring: color-mix(in srgb, var(--accent) 72%, var(--cyan));
}

html[data-theme="light"] {
  --panel-3: #e7e7e2;
  --muted: #62625f;
  --soft: #30302d;
  --danger: #c83f4d;
  --ok: #16764a;
  --cyan: #14698f;
  --cm-shadow-sm: 0 8px 24px rgba(45, 45, 35, .09);
  --cm-shadow-md: 0 18px 52px rgba(45, 45, 35, .13);
  --cm-shadow-lg: 0 32px 100px rgba(45, 45, 35, .2);
}

html,
body {
  min-height: 100%;
  background-color: var(--bg);
}

body {
  background:
    radial-gradient(circle at 12% 8%, var(--cm-aurora-a), transparent 34rem),
    radial-gradient(circle at 88% 18%, var(--cm-aurora-b), transparent 30rem),
    radial-gradient(circle at 54% 110%, var(--cm-aurora-c), transparent 34rem),
    var(--bg);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  text-rendering: optimizeLegibility;
}

::selection {
  background: color-mix(in srgb, var(--accent) 32%, var(--cyan));
  color: var(--text);
}

/* Controls, focus and icon language ------------------------------------- */
button,
input,
select,
textarea {
  border-radius: var(--cm-radius-sm);
}

input,
select {
  min-height: 46px;
  border-color: var(--cm-line-soft);
  background: var(--cm-surface-soft);
  transition: border-color var(--cm-motion-fast) ease, box-shadow var(--cm-motion-fast) ease, background var(--cm-motion-fast) ease;
}

textarea {
  border-color: var(--cm-line-soft);
  border-radius: var(--cm-radius-md);
  background: var(--cm-surface-soft);
}

.rail-icon,
.icon-button,
.tiny-button,
.tool-button,
.control-button,
.danger-button,
.primary-action,
.modal-actions button,
.selection-bar button,
.message-retry,
.message-discard,
.emoji-button {
  min-width: var(--cm-control-size);
  min-height: var(--cm-control-size);
  border-radius: var(--cm-radius-sm);
}

.icon-button {
  width: var(--cm-control-size);
  height: var(--cm-control-size);
}

.tiny-button {
  width: 40px;
  height: var(--cm-control-size);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--cm-ring);
  outline-offset: 3px;
  border-color: var(--cm-ring);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--cm-ring) 18%, transparent), var(--cm-shadow-sm);
}

[data-icon]::before {
  width: 20px;
  height: 20px;
}

.emoji-button[data-icon],
.message-retry[data-icon],
.message-discard[data-icon],
.quick-switch-row [data-icon] {
  position: relative;
  display: inline-grid;
  place-items: center;
  font-size: 0;
}

[data-icon="search"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10.5 3a7.5 7.5 0 1 0 4.7 13.35L20.85 22 22 20.85l-5.65-5.65A7.5 7.5 0 0 0 10.5 3Zm0 2a5.5 5.5 0 1 1 0 11 5.5 5.5 0 0 1 0-11Z'/%3E%3C/svg%3E"); }
[data-icon="smile"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm0 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16ZM8 9a1.25 1.25 0 1 0 0 2.5A1.25 1.25 0 0 0 8 9Zm8 0a1.25 1.25 0 1 0 0 2.5A1.25 1.25 0 0 0 16 9Zm-8.2 5h2.05c.38 1.15 1.18 1.75 2.15 1.75s1.77-.6 2.15-1.75h2.05c-.48 2.35-2.1 3.75-4.2 3.75S8.28 16.35 7.8 14Z'/%3E%3C/svg%3E"); }
[data-icon="check"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9.4 18.2-5.6-5.6 1.8-1.8 3.8 3.8 9-9 1.8 1.8-10.8 10.8Z'/%3E%3C/svg%3E"); }
[data-icon="retry"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.8 7.2V3.5h2V11H14.3V9h4a7 7 0 1 0 .35 5.2h2.1A9 9 0 1 1 19.8 7.2Z'/%3E%3C/svg%3E"); }
[data-icon="trash"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 3h6l1 2h5v2H3V5h5l1-2Zm-3 6h12l-1 12H7L6 9Zm3 2 .5 8h1L10 11H9Zm5 0-.5 8h1L15 11h-1Z'/%3E%3C/svg%3E"); }
[data-icon="close"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6.4 5 5.6 5.6L17.6 5 19 6.4 13.4 12l5.6 5.6-1.4 1.4-5.6-5.6L6.4 19 5 17.6l5.6-5.6L5 6.4 6.4 5Z'/%3E%3C/svg%3E"); }
[data-icon="sparkles"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m12 2 1.2 3.8L17 7l-3.8 1.2L12 12l-1.2-3.8L7 7l3.8-1.2L12 2Zm6 9 1 3 3 1-3 1-1 3-1-3-3-1 3-1 1-3ZM7 13l1.3 3.7L12 18l-3.7 1.3L7 23l-1.3-3.7L2 18l3.7-1.3L7 13Z'/%3E%3C/svg%3E"); }
[data-icon="back"] { --icon-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m10 4 1.4 1.4L5.8 11H21v2H5.8l5.6 5.6L10 20l-8-8 8-8Z'/%3E%3C/svg%3E"); }

/* Authentication and boot scene ---------------------------------------- */
.auth-shell {
  width: min(1180px, 100%);
  margin-inline: auto;
  grid-template-columns: minmax(0, 460px);
  place-items: center stretch;
  gap: clamp(24px, 5vw, 68px);
  padding: clamp(20px, 4vw, 48px);
}

.auth-shell:has(.auth-showcase) {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 460px);
}

.auth-panel,
.auth-showcase {
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-xl);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-lg), inset 0 1px 0 color-mix(in srgb, var(--text) 10%, transparent);
  backdrop-filter: blur(24px) saturate(1.16);
}

.auth-panel {
  width: 100%;
  padding: clamp(22px, 4vw, 34px);
}

.auth-showcase {
  position: relative;
  min-height: 520px;
  display: grid;
  align-content: end;
  gap: 18px;
  overflow: hidden;
  padding: clamp(28px, 5vw, 54px);
  background:
    radial-gradient(circle at 22% 18%, var(--cm-accent-medium), transparent 18rem),
    radial-gradient(circle at 88% 72%, color-mix(in srgb, var(--cyan) 20%, transparent), transparent 20rem),
    var(--cm-glass);
}

.auth-showcase::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  border-radius: calc(var(--cm-radius-xl) - 8px);
  pointer-events: none;
}

.auth-showcase > * { position: relative; z-index: 1; }
.auth-showcase h1 { margin: 0; max-width: 11ch; font-size: clamp(36px, 5vw, 68px); line-height: .98; letter-spacing: -.045em; }
.auth-showcase p { max-width: 52ch; margin: 0; color: var(--soft); line-height: 1.65; }

.feature-pill {
  width: fit-content;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-pill);
  background: var(--cm-surface-soft);
  color: var(--soft);
  font-size: 12px;
  font-weight: 850;
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 8%, transparent);
}

.brand-mark img,
.rail-logo { filter: drop-shadow(0 10px 28px var(--cm-accent-medium)); }
.auth-tabs { padding: 5px; border-radius: var(--cm-radius-md); background: var(--cm-surface-soft); }
.auth-tabs button { min-height: 44px; border-radius: var(--cm-radius-sm); }
.auth-tabs button.active { box-shadow: var(--cm-shadow-sm); }

.boot-screen {
  background:
    radial-gradient(circle at 50% 35%, var(--cm-accent-medium), transparent 18rem),
    radial-gradient(circle at 35% 75%, var(--cm-aurora-b), transparent 22rem),
    var(--bg);
  color: var(--text);
}

/* Main application shell ------------------------------------------------ */
.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  grid-template-columns: var(--cm-rail-width) var(--cm-sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  background: transparent;
}

.rail {
  min-height: 0;
  padding: 14px 10px;
  gap: 10px;
  border-right-color: var(--cm-line-soft);
  background: var(--cm-glass-strong);
  backdrop-filter: blur(22px) saturate(1.14);
}

.rail-logo { width: 48px; height: 48px; margin-bottom: 6px; }

.rail-icon {
  position: relative;
  width: 50px;
  height: 48px;
  border-color: transparent;
  border-radius: var(--cm-radius-md);
  background: transparent;
  color: var(--muted);
}

.rail-icon::after {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  width: 4px;
  height: 10px;
  border-radius: var(--cm-radius-pill);
  background: var(--accent);
  opacity: 0;
  transform: translateY(-50%) scaleY(.5);
  transition: opacity var(--cm-motion-fast) ease, height var(--cm-motion-ui) var(--cm-ease-spring), transform var(--cm-motion-ui) var(--cm-ease-spring);
}

.rail-icon.active,
.rail-icon[aria-current="page"] {
  border-color: var(--cm-line-strong);
  background: linear-gradient(145deg, var(--cm-accent-soft), var(--cm-surface-soft));
  color: var(--text);
  box-shadow: var(--cm-shadow-sm), inset 0 1px 0 color-mix(in srgb, var(--text) 12%, transparent);
}

.rail-icon.active::after,
.rail-icon[aria-current="page"]::after { height: 28px; opacity: 1; transform: translateY(-50%) scaleY(1); }

.sidebar {
  min-height: 0;
  border-right-color: var(--cm-line-soft);
  background: var(--cm-glass);
  backdrop-filter: blur(22px) saturate(1.12);
}

.sidebar-view.active { animation: cmPanelEnter var(--cm-motion-ui) var(--cm-ease-standard) both; }

.sidebar-header,
.chat-header {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom-color: var(--cm-line-soft);
}

.sidebar-header strong { font-size: 20px; letter-spacing: -.025em; }
.sidebar-scroll { padding: 8px 12px 16px; }
.section-title { padding: 13px 6px 7px; }
.friends-list { gap: 6px; }

.friend-item,
.request-item,
.group-member-row,
.search-row {
  position: relative;
  min-height: 54px;
  border-radius: var(--cm-radius-md);
  transition: background var(--cm-motion-fast) ease, border-color var(--cm-motion-fast) ease, transform var(--cm-motion-fast) ease, box-shadow var(--cm-motion-fast) ease;
}

.friend-item { padding: 8px 9px; overflow: hidden; }
.friend-item::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  width: 3px;
  height: 10px;
  border-radius: var(--cm-radius-pill);
  background: var(--accent);
  opacity: 0;
  transform: translateY(-50%);
  transition: height var(--cm-motion-ui) var(--cm-ease-spring), opacity var(--cm-motion-fast) ease;
}

.friend-item.active,
.friend-item[aria-current="true"] {
  border-color: var(--cm-line-strong);
  background: linear-gradient(105deg, var(--cm-accent-soft), var(--cm-surface-soft) 72%);
  box-shadow: var(--cm-shadow-sm), inset 0 1px 0 color-mix(in srgb, var(--text) 8%, transparent);
}

.friend-item.active::before,
.friend-item[aria-current="true"]::before { height: 30px; opacity: 1; }
.friend-item .avatar { transition: transform var(--cm-motion-ui) var(--cm-ease-spring), box-shadow var(--cm-motion-ui) ease; }
.friend-item.active .avatar { transform: scale(1.04); box-shadow: 0 0 0 3px var(--cm-accent-soft); }

.presence { box-shadow: 0 0 0 3px var(--cm-surface-raised); }
.profile-footer {
  min-height: 78px;
  padding: 12px;
  border-top-color: var(--cm-line-soft);
  background: var(--cm-glass-strong);
  backdrop-filter: blur(20px);
}
.profile-button { min-height: 50px; border-radius: var(--cm-radius-md); padding: 5px; }

.search-box { padding: 12px 12px 8px; }
.search-box input { min-height: 46px; padding-left: 14px; border-radius: var(--cm-radius-pill); background: var(--cm-surface-soft); }
.search-results { top: 62px; border-radius: var(--cm-radius-lg); border-color: var(--cm-line-soft); background: var(--cm-glass-strong); box-shadow: var(--cm-shadow-md); backdrop-filter: blur(22px); }

/* Chat canvas, messages and activity ------------------------------------ */
.chat-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
  background:
    radial-gradient(circle at 84% -10%, var(--cm-aurora-a), transparent 30rem),
    radial-gradient(circle at 8% 105%, var(--cm-aurora-b), transparent 32rem),
    linear-gradient(color-mix(in srgb, var(--text) 2%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--text) 2%, transparent) 1px, transparent 1px),
    var(--bg);
  background-size: auto, auto, 32px 32px, 32px 32px, auto;
  overflow: hidden;
}

.chat-shell > .chat-header { grid-row: 1; }
.chat-shell > .call-panel { grid-row: 2; }
.chat-shell > .messages { grid-row: 3; }
.chat-shell > .chat-activity { grid-row: 4; }
.chat-shell > .selection-bar { grid-row: 5; }
.chat-shell > .pending-attachments { grid-row: 6; }
.chat-shell > .message-form { grid-row: 7; }

.chat-header {
  position: relative;
  z-index: 12;
  min-width: 0;
  padding-inline: clamp(14px, 2vw, 22px);
  background: var(--cm-glass-strong);
  backdrop-filter: blur(24px) saturate(1.16);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .08);
}

.chat-identity { min-width: 0; gap: 12px; }
.chat-identity > div { min-width: 0; }
.chat-identity strong,
.chat-identity span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-identity strong { font-size: 17px; letter-spacing: -.015em; }
.call-actions { flex: 0 0 auto; align-items: center; gap: 8px; }
.split-action .icon-button { width: 52px; height: var(--cm-control-size); border-radius: var(--cm-radius-sm) 0 0 var(--cm-radius-sm); }
.split-action .tiny-button { border-radius: 0 var(--cm-radius-sm) var(--cm-radius-sm) 0; }

.messages {
  padding: 22px clamp(14px, 3vw, 34px);
  gap: 10px;
  scroll-padding-block: 24px;
}

.message {
  position: relative;
  max-width: min(820px, 82%);
  animation: none;
  transition: transform var(--cm-motion-fast) ease, filter var(--cm-motion-fast) ease, opacity var(--cm-motion-ui) ease;
}

.message.new-message,
.message.is-entering { animation: cmMessageEnter 340ms var(--cm-ease-spring) both; }

.message-bubble {
  position: relative;
  border-color: var(--cm-line-soft);
  border-radius: 24px 24px 24px 9px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--panel-2) 88%, var(--text) 4%), color-mix(in srgb, var(--panel) 94%, transparent));
  padding: 11px 14px;
  box-shadow: var(--cm-shadow-sm), inset 0 1px 0 color-mix(in srgb, var(--text) 9%, transparent);
  backdrop-filter: none;
}

.message.mine .message-bubble {
  border-radius: 24px 24px 9px 24px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 78%, var(--cyan)));
  color: var(--accent-text);
  box-shadow: 0 12px 34px color-mix(in srgb, var(--accent) 20%, transparent), inset 0 1px 0 color-mix(in srgb, #fff 26%, transparent);
}

.message.mine .message-meta,
.message.mine .link-preview-card small,
.message.mine .link-preview-card em { color: color-mix(in srgb, var(--accent-text) 68%, transparent); }
.message.mine .message-link { color: var(--accent-text); border-bottom-color: color-mix(in srgb, var(--accent-text) 44%, transparent); }
.message-meta { margin-bottom: 3px; font-size: 11px; letter-spacing: .01em; }

.message.selected .message-bubble {
  outline: 3px solid var(--cm-ring);
  outline-offset: 3px;
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--cm-ring) 12%, transparent), var(--cm-shadow-md);
}

.message.selected::after {
  content: "✓";
  position: absolute;
  right: -8px;
  top: -8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 3px solid var(--bg);
  border-radius: var(--cm-radius-pill);
  background: var(--cm-ring);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 950;
}

.message.is-pending { opacity: .72; }
.message.is-pending .message-bubble { border-style: dashed; }
.message.is-failed { opacity: 1; }
.message.is-failed .message-bubble { border-color: color-mix(in srgb, var(--danger) 70%, var(--line)); box-shadow: 0 0 0 4px var(--cm-danger-soft), var(--cm-shadow-sm); }
.message.is-sent { opacity: 1; }

.delivery-state {
  min-width: 18px;
  min-height: 18px;
  display: inline-grid;
  place-items: center;
  margin-inline-start: 5px;
  border-radius: var(--cm-radius-pill);
  color: currentColor;
  font-size: 10px;
  font-weight: 950;
  vertical-align: -4px;
}

.message.is-pending .delivery-state::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--cm-radius-pill);
  animation: cmSpin .75s linear infinite;
}
.message.is-sent .delivery-state::before { content: "✓"; }
.message.is-failed .delivery-state::before { content: "!"; color: var(--danger); }

.message-retry,
.message-discard {
  display: inline-grid;
  place-items: center;
  margin: 7px 4px 0 0;
  border: 1px solid var(--cm-line-soft);
  background: var(--cm-surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
}
.message-retry { border-color: color-mix(in srgb, var(--accent) 46%, var(--line)); }
.message-discard { color: var(--danger); }

.empty-state { padding: 24px; border-radius: var(--cm-radius-lg); }
.empty-state strong { font-size: clamp(25px, 4vw, 38px); letter-spacing: -.035em; }

.sync-status {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-pill);
  background: var(--cm-surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}
.sync-status::before { content: ""; width: 8px; height: 8px; border-radius: var(--cm-radius-pill); background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 10%, transparent); }
.sync-status.online { color: var(--ok); }
.sync-status.offline { color: var(--danger); }
.sync-status.syncing { color: var(--cyan); }
.sync-status.syncing::before { animation: cmSyncPulse 1.2s ease-in-out infinite; }

.chat-activity {
  min-height: 30px;
  display: flex;
  align-items: center;
  padding: 3px clamp(18px, 3vw, 36px);
  color: var(--muted);
  font-size: 12px;
}
.typing-indicator { display: inline-flex; align-items: center; gap: 8px; }
.typing-dots { height: 18px; display: inline-flex; align-items: center; gap: 3px; }
.typing-dots span { width: 5px; height: 5px; border-radius: var(--cm-radius-pill); background: var(--muted); animation: cmTypingDot 1s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: 120ms; }
.typing-dots span:nth-child(3) { animation-delay: 240ms; }

/* Composer and selection ------------------------------------------------ */
.selection-bar {
  position: relative;
  z-index: 11;
  min-height: 58px;
  margin: 10px 14px 0;
  padding: 7px 9px 7px 14px;
  border: 1px solid var(--cm-line-strong);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-md), inset 0 1px 0 color-mix(in srgb, var(--text) 10%, transparent);
  backdrop-filter: blur(22px);
  animation: cmToolbarEnter var(--cm-motion-ui) var(--cm-ease-spring) both;
}
.selection-bar strong { font-size: 13px; }
.selection-bar button { border-color: transparent; border-radius: var(--cm-radius-sm); background: var(--cm-surface-soft); }
#deleteMeButton,
#deleteAllButton { color: var(--danger); background: var(--cm-danger-soft); }
#cancelSelectionButton { background: transparent; }

.pending-attachments {
  margin: 8px 14px 0;
  padding: 9px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  backdrop-filter: blur(18px);
}
.pending-card { width: 78px; height: 78px; border-radius: var(--cm-radius-md); background: var(--cm-surface-raised); }

.message-form {
  z-index: 10;
  grid-template-columns: 46px 46px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 8px;
  margin: 10px 14px 14px;
  padding: 8px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-md), inset 0 1px 0 color-mix(in srgb, var(--text) 9%, transparent);
  backdrop-filter: blur(24px) saturate(1.12);
}

.message-form input,
.message-form button { min-height: 46px; }

.message-form #messageInput {
  min-width: 0;
  border-color: transparent;
  border-radius: var(--cm-radius-pill);
  background: var(--cm-surface-soft);
  box-shadow: none;
}

.message-form .tool-button,
.message-form .emoji-button {
  border: 1px solid transparent;
  border-radius: var(--cm-radius-md);
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.message-form .tool-button:hover,
.message-form .emoji-button:hover { border-color: var(--cm-line-soft); background: var(--cm-surface-soft); color: var(--text); }

.composer-input-wrap {
  position: relative;
  min-width: 0;
  min-height: 46px;
  height: 46px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--cm-radius-pill);
  background: var(--cm-surface-soft);
}
.composer-input-wrap:focus-within { border-color: var(--cm-ring); box-shadow: 0 0 0 4px color-mix(in srgb, var(--cm-ring) 13%, transparent); }
.composer-input-wrap #messageInput { height: 44px; min-height: 44px; border: 0; background: transparent; box-shadow: none; }
.composer-input-wrap .emoji-button { align-self: center; min-width: 38px; min-height: 38px; }

.emoji-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 40;
  width: min(330px, calc(100vw - 28px));
  max-height: min(340px, 48vh);
  display: grid;
  grid-template-columns: repeat(8, minmax(32px, 1fr));
  gap: 4px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-lg);
  backdrop-filter: blur(24px);
  transform-origin: right bottom;
  animation: cmMenuEnter var(--cm-motion-ui) var(--cm-ease-spring) both;
}
.emoji-menu button { min-width: 36px; min-height: 36px; border: 0; border-radius: var(--cm-radius-sm); background: transparent; color: var(--text); font-size: 20px; }
.emoji-menu button:hover { background: var(--cm-accent-soft); transform: scale(1.08); }

#messageSend {
  position: relative;
  width: 48px;
  min-width: 48px;
  border-radius: var(--cm-radius-md);
  overflow: visible;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 23%, transparent);
}
#messageSend::after { content: ""; position: absolute; inset: 4px; border: 2px solid var(--accent); border-radius: inherit; opacity: 0; pointer-events: none; }
#messageSend.send-burst::before { animation: cmSendBurst 440ms var(--cm-ease-spring) both; }
#messageSend.send-burst::after { animation: cmSendRipple 440ms ease-out both; }

.chat-shell.chat-switching .chat-header { animation: cmChatHeaderSwitch var(--cm-motion-ui) var(--cm-ease-standard) both; }
.chat-shell.chat-switching .messages { animation: cmChatCanvasSwitch var(--cm-motion-ui) var(--cm-ease-standard) both; }

/* Menus, modals, settings and quick switch ------------------------------ */
.attach-menu,
.stream-menu,
.moderation-menu,
.message-action-card,
.toast {
  border-color: var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-lg), inset 0 1px 0 color-mix(in srgb, var(--text) 9%, transparent);
  backdrop-filter: blur(24px) saturate(1.12);
}

.attach-menu button,
.stream-menu button,
.moderation-menu button { border-radius: var(--cm-radius-sm); }

.modal,
.quick-switch-dialog {
  border: 1px solid var(--cm-line-strong);
  border-radius: var(--cm-radius-lg);
  background: var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-lg), inset 0 1px 0 color-mix(in srgb, var(--text) 10%, transparent);
  backdrop-filter: blur(28px) saturate(1.16);
}
.modal { padding: clamp(20px, 3vw, 28px); }
.modal::backdrop,
.quick-switch-dialog::backdrop { background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(12px) saturate(.8); }
.modal h2 { letter-spacing: -.025em; }
.modal-actions { flex-wrap: wrap; gap: 9px; }
.modal-actions button { padding-inline: 16px; }

.settings-page-form { padding: 12px; gap: 12px; }
.settings-group {
  gap: 11px;
  padding: 15px;
  border-color: var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background: linear-gradient(145deg, var(--cm-surface-soft), color-mix(in srgb, var(--panel) 90%, transparent));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 8%, transparent);
}
.settings-group h3 { font-size: 14px; letter-spacing: -.01em; }
.theme-preview,
.member-picker,
.profile-view-head,
.group-profile-tools,
.profile-editor-preview { border-color: var(--cm-line-soft); border-radius: var(--cm-radius-md); background: var(--cm-surface-soft); }
.check-row { min-height: 44px; padding: 7px 4px; }
.check-row input { min-height: 20px; width: 20px; }

.quick-switch-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: min(720px, calc(100dvh - 48px));
  padding: 12px;
  color: var(--text);
  overflow: hidden;
}
.quick-switch-input { width: 100%; min-height: 54px; padding: 0 18px; border-radius: var(--cm-radius-md); font-size: 16px; background: var(--cm-surface-soft); }
.quick-switch-results { max-height: min(60vh, 560px); display: grid; gap: 5px; overflow: auto; padding: 8px 2px 2px; }
.quick-switch-row {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: var(--cm-radius-md);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.quick-switch-row:hover,
.quick-switch-row.active,
.quick-switch-row[aria-selected="true"] { border-color: var(--cm-line-strong); background: var(--cm-accent-soft); }

/* Welcome/onboarding scene --------------------------------------------- */
.welcome-scene {
  width: min(760px, 100%);
  margin: auto;
  display: grid;
  place-items: center;
  padding: clamp(14px, 4vw, 40px);
  animation: cmSceneEnter var(--cm-motion-scene) var(--cm-ease-standard) both;
}
.scene-card {
  position: relative;
  width: 100%;
  display: grid;
  gap: 18px;
  overflow: hidden;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid var(--cm-line-strong);
  border-radius: var(--cm-radius-xl);
  background:
    radial-gradient(circle at 82% 12%, var(--cm-accent-medium), transparent 17rem),
    radial-gradient(circle at 4% 94%, var(--cm-aurora-b), transparent 20rem),
    var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-lg), inset 0 1px 0 color-mix(in srgb, var(--text) 12%, transparent);
  backdrop-filter: blur(24px);
}
.scene-card h1,
.scene-card h2 { max-width: 15ch; margin: 0; font-size: clamp(29px, 5vw, 52px); line-height: 1.02; letter-spacing: -.04em; }
.scene-card p { max-width: 58ch; margin: 0; color: var(--soft); line-height: 1.65; }
.scene-step { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; font-weight: 850; }
.scene-step::before { content: ""; width: 26px; height: 5px; border-radius: var(--cm-radius-pill); background: var(--cm-line-strong); }
.scene-step.active { color: var(--text); }
.scene-step.active::before { background: var(--accent); box-shadow: 0 0 16px var(--cm-accent-medium); }
.scene-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.scene-actions button { min-height: 46px; padding: 0 18px; border-radius: var(--cm-radius-sm); }

/* Calls, media and overlays -------------------------------------------- */
.call-panel {
  margin: 10px 14px 0;
  padding: 14px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-lg);
  background:
    radial-gradient(circle at 80% 0, var(--cm-aurora-c), transparent 20rem),
    var(--cm-glass-strong);
  box-shadow: var(--cm-shadow-md);
  backdrop-filter: blur(22px);
}
.call-panel.hidden { display: none !important; }
.call-card { min-height: 124px; border-color: var(--cm-line-soft); border-radius: var(--cm-radius-lg); background: var(--cm-surface-soft); }
.call-card .avatar { border-radius: var(--cm-radius-md); }
.call-card.speaking { transform: translateY(-2px); box-shadow: 0 0 0 3px var(--cm-ok-soft), 0 16px 40px var(--cm-ok-soft); }
.video-grid { border-color: var(--cm-line-soft); border-radius: var(--cm-radius-lg); background: color-mix(in srgb, var(--bg) 88%, #000); }
.video-grid video,
.remote-frame-stream { border-radius: var(--cm-radius-md); }
.call-bar { min-height: 54px; padding: 8px; border-radius: var(--cm-radius-md); background: var(--cm-surface-soft); }
.call-bar button { min-height: 42px; }
.call-join-banner { border-radius: var(--cm-radius-md); background: var(--cm-ok-soft); box-shadow: var(--cm-shadow-sm); }
.ringing-card,
.incoming-card { border-radius: var(--cm-radius-md); background: var(--cm-surface-soft); }
.media-viewer-stage img,
.media-viewer-stage video { border-radius: var(--cm-radius-lg); }
.media-close { width: 46px; height: 46px; border-radius: var(--cm-radius-md); }
.toast { right: 20px; bottom: 20px; min-height: 46px; display: flex; align-items: center; padding: 10px 15px; }

.message-action-overlay { background: color-mix(in srgb, var(--bg) 44%, transparent); }
.message-action-card { border-radius: var(--cm-radius-lg); }
.message-action-close { width: 40px; height: 40px; border-radius: var(--cm-radius-sm); }

.chat-shell.stream-focus { grid-template-rows: auto minmax(0, min(68vh, 720px)) minmax(120px, 1fr) auto auto auto auto; }
.chat-shell.stream-focus .call-panel { margin-top: 10px; padding: 12px; }

/* Theme-specific corrections for older high-specificity rules ---------- */
html[data-theme="light"] :is(.rail, .sidebar, .profile-footer, .chat-header, .message-form, .call-panel, .modal, .toast, .search-results, .attach-menu, .stream-menu, .moderation-menu, .emoji-menu, .quick-switch-dialog) {
  background-color: var(--cm-glass-strong);
  color: var(--text);
}

html[data-theme="light"] :is(input, select, textarea, .member-picker, .profile-view-head, .group-profile-tools, .profile-editor-preview) {
  background-color: var(--cm-surface-soft);
  color: var(--text);
}

html[data-theme="custom"] :is(.rail, .sidebar, .profile-footer, .chat-header, .message-form, .call-panel, .modal, .search-results, .attach-menu, .emoji-menu, .quick-switch-dialog) {
  border-color: var(--cm-line-soft);
}

/* Responsive layout ----------------------------------------------------- */
@media (min-width: 561px) and (max-width: 1050px) {
  html,
  body { height: 100%; overflow: hidden; }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: 64px clamp(216px, 32vw, 300px) minmax(0, 1fr);
    transform: none;
    overflow: hidden;
  }

  .rail,
  .sidebar,
  .chat-shell { min-height: 0; height: 100dvh; }
  .rail { grid-column: 1; padding-inline: 7px; }
  .sidebar { grid-column: 2; }
  .chat-shell { grid-column: 3; }
  .rail-logo { width: 44px; height: 44px; }
  .rail-icon { width: 48px; }
  .sidebar-header,
  .chat-header { padding-inline: 12px; }
  .chat-identity span { max-width: min(34vw, 300px); }
  .call-actions { gap: 5px; }
  .message { max-width: 90%; }
  .messages { padding-inline: 16px; }
  .message-form { margin-inline: 10px; }
  .call-panel { margin-inline: 10px; }
}

@media (max-width: 760px) and (min-width: 561px) {
  .app-shell { grid-template-columns: 60px 212px minmax(0, 1fr); }
  .chat-header { align-items: center; }
  .chat-identity span { display: none; }
  .call-actions .icon-button { width: 42px; min-width: 42px; }
  .split-action .tiny-button { width: 34px; min-width: 34px; }
  .message-form { grid-template-columns: 42px 42px minmax(0, 1fr) 46px; gap: 5px; }
}

@media (max-width: 900px) {
  .auth-shell:has(.auth-showcase) { grid-template-columns: minmax(0, 1fr); }
  .auth-showcase { min-height: 330px; }
}

@media (max-width: 560px) {
  html,
  body { width: 100%; height: 100%; overflow: hidden; }

  .app-shell {
    --mobile-rail: 56px;
    --mobile-sidebar: calc(100vw - var(--mobile-rail));
    width: 200vw;
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: var(--mobile-rail) var(--mobile-sidebar) 100vw;
    transform: translateX(0);
    transition: transform 260ms var(--cm-ease-standard);
    overflow: hidden;
  }

  .app-shell.chat-open { transform: translateX(-100vw); }
  .rail { min-height: 100dvh; height: 100dvh; padding-inline: 5px; }
  .rail-icon { width: 44px; height: 44px; }
  .rail-icon::after { left: -5px; }
  .sidebar { min-height: 100dvh; height: 100dvh; grid-template-rows: minmax(0, 1fr) auto; }
  .chat-shell { min-height: 100dvh; height: 100dvh; grid-column: 3; }

  .chat-header {
    min-height: calc(68px + env(safe-area-inset-top));
    flex-direction: row;
    align-items: center;
    padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  }
  .chat-identity { flex: 1 1 auto; overflow: hidden; }
  .chat-identity .avatar { width: 34px; height: 34px; }
  .chat-identity span { max-width: 42vw; }
  .call-actions { margin-left: auto; }
  .call-actions .icon-button { width: 42px; min-width: 42px; height: 42px; min-height: 42px; }
  .split-action .tiny-button { width: 32px; min-width: 32px; height: 42px; min-height: 42px; }
  [data-icon="back"],
  .mobile-back-button { display: inline-grid; flex: 0 0 auto; }

  .messages { padding: 16px 10px; }
  .message { max-width: 94%; }
  .message-bubble { border-radius: 20px 20px 20px 8px; }
  .message.mine .message-bubble { border-radius: 20px 20px 8px 20px; }

  .message-form {
    grid-template-columns: 42px 42px minmax(0, 1fr) 46px;
    gap: 5px;
    margin: 8px 8px calc(8px + env(safe-area-inset-bottom));
    padding: 6px;
    border-radius: 20px;
  }
  .message-form input,
  .message-form button { min-height: 44px; }
  #messageSend { width: 46px; min-width: 46px; }
  .emoji-menu { right: -52px; grid-template-columns: repeat(7, minmax(32px, 1fr)); }

  .selection-bar { margin: 8px 8px 0; padding: 9px; border-radius: 20px; }
  .selection-bar strong { width: 100%; }
  .selection-bar button { flex: 1 1 44%; }
  .pending-attachments { margin-inline: 8px; }
  .call-panel { margin: 8px 8px 0; padding: 9px; border-radius: 20px; }
  .call-bar { justify-content: center; }
  #callStatus { flex: 1 0 100%; text-align: center; }
  .call-card { min-height: 104px; }

  .modal,
  .quick-switch-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); border-radius: 22px; }
  .modal-actions { align-items: stretch; }
  .modal-actions button { flex: 1 1 42%; }
  .quick-switch-dialog { padding: 9px; }

  .auth-shell { min-height: 100dvh; padding: 12px; }
  .auth-showcase { display: none; }
  .auth-panel { border-radius: 24px; }
  .welcome-scene { padding: 10px; }
  .scene-card { padding: 24px; border-radius: 24px; }
  .scene-actions button { flex: 1 1 44%; }

  .toast { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); justify-content: center; }
}

@media (max-width: 380px) {
  .message-form { grid-template-columns: 40px 40px minmax(0, 1fr) 44px; }
  .call-actions { gap: 3px; }
  .call-actions .icon-button { width: 38px; min-width: 38px; }
  .chat-identity span { display: none; }
  .emoji-menu { grid-template-columns: repeat(6, minmax(32px, 1fr)); }
}

@media (hover: hover) and (pointer: fine) {
  .rail-icon:hover { border-color: var(--cm-line-strong); background: var(--cm-surface-soft); color: var(--text); transform: translateY(-2px); }
  .friend-item:hover,
  .request-item:hover,
  .quick-switch-row:hover { background: var(--cm-surface-hover); transform: translateY(-1px); }
}

@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .rail,
  .sidebar,
  .chat-header,
  .profile-footer,
  .message-form,
  .selection-bar,
  .call-panel,
  .modal,
  .quick-switch-dialog,
  .attach-menu,
  .emoji-menu { background: var(--cm-surface-raised); }
}

/* Motion ---------------------------------------------------------------- */
@keyframes cmPanelEnter { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes cmMessageEnter { 0% { opacity: 0; transform: translateY(11px) scale(.975); } 68% { opacity: 1; transform: translateY(-1px) scale(1.004); } 100% { opacity: 1; transform: none; } }
@keyframes cmToolbarEnter { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes cmMenuEnter { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes cmSceneEnter { from { opacity: 0; transform: translateY(18px) scale(.98); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes cmSpin { to { transform: rotate(360deg); } }
@keyframes cmSyncPulse { 0%, 100% { opacity: .45; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.18); } }
@keyframes cmTypingDot { 0%, 60%, 100% { opacity: .4; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
@keyframes cmSendBurst { 0% { opacity: 1; transform: translate(0, 0) scale(1); } 45% { opacity: 0; transform: translate(12px, -12px) scale(.72) rotate(-8deg); } 46% { opacity: 0; transform: translate(-8px, 8px) scale(.72); } 100% { opacity: 1; transform: none; } }
@keyframes cmSendRipple { 0% { opacity: .55; transform: scale(.72); } 100% { opacity: 0; transform: scale(1.55); } }
@keyframes cmChatHeaderSwitch { from { opacity: .55; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
@keyframes cmChatCanvasSwitch { from { opacity: .32; transform: translateX(8px); } to { opacity: 1; transform: none; } }

/* One complete escape hatch for users who reduce motion. */
@media (prefers-reduced-motion: reduce) {
  html:focus-within { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }

  .message,
  .message.new-message,
  .message.is-entering,
  .chat-shell.chat-switching .chat-header,
  .chat-shell.chat-switching .messages,
  .welcome-scene,
  .sidebar-view.active,
  .selection-bar,
  .emoji-menu,
  .attach-menu,
  .ringing-card::before,
  .ring-avatar span,
  .ring-avatar i,
  .presence.online,
  .typing-dots span,
  .sync-status.syncing::before,
  .voice-wave span,
  .chat-call-icon,
  .boot-logo,
  .boot-logo img,
  .boot-logo span,
  .app-loading-spinner,
  .theme-wave,
  #messageSend.send-burst::before,
  #messageSend.send-burst::after {
    animation: none !important;
    transform: none !important;
  }

  .theme-wave { display: none !important; }
  .app-shell { scroll-behavior: auto; }
}

/* CatMat 0.1.31 interaction details ------------------------------------ */
.auth-showcase { grid-template-rows: auto minmax(0, 1fr) auto; align-content: stretch; }
.auth-showcase > div:nth-child(2) { align-self: end; display: grid; gap: 14px; }
.showcase-brand { position: relative; display: inline-flex; align-items: center; gap: 10px; color: var(--soft); font-size: 11px; font-weight: 950; letter-spacing: .15em; }
.showcase-brand img { width: 38px; height: 38px; object-fit: contain; filter: drop-shadow(0 8px 20px var(--cm-accent-medium)); }
.showcase-kicker { color: color-mix(in srgb, var(--accent) 78%, var(--text)); font-size: 11px; font-weight: 950; letter-spacing: .13em; text-transform: uppercase; }
.feature-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.feature-pill [data-icon],
.empty-spark[data-icon],
.quick-switch-row > [data-icon] { width: 19px; height: 19px; display: inline-grid; place-items: center; color: var(--accent); }
.feature-pill [data-icon]::before,
.empty-spark[data-icon]::before,
.quick-switch-row > [data-icon]::before { display: block; }

.mobile-back-button { display: none; }
.sync-status strong { font-size: inherit; }
.quick-switch-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 5px 4px 14px; }
.quick-switch-head span { color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.quick-switch-head h2 { margin: 3px 0 0; font-size: 23px; letter-spacing: -.025em; }
.quick-switch-row > .avatar { width: 40px; height: 40px; }

.hero-empty { display: grid; justify-items: center; gap: 12px; padding: clamp(28px, 6vw, 58px); border: 1px solid var(--cm-line-soft); background: radial-gradient(circle at 50% 0, var(--cm-accent-soft), transparent 16rem), var(--cm-surface-soft); box-shadow: var(--cm-shadow-md); }
.hero-empty p { max-width: 42ch; margin: 0; }
.empty-spark { width: 58px !important; height: 58px !important; border: 1px solid var(--cm-line-strong); border-radius: 20px; background: var(--cm-accent-soft); box-shadow: 0 16px 42px var(--cm-accent-medium); }
.empty-spark::before { width: 28px; height: 28px; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; margin-top: 5px; }
.empty-actions button { min-height: 44px; padding: 0 16px; }

.message-delivery { min-height: 20px; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.delivery-label { color: color-mix(in srgb, currentColor 62%, transparent); font-size: 10px; font-weight: 800; }
.error-label { max-width: 260px; color: var(--danger); }
.message-retry,
.message-discard { min-width: 34px; min-height: 30px; margin-top: 3px; }
.message.is-sent .delivery-state::before { content: "\2713"; }
.message.selected::after { content: "\2713"; }

.welcome-scene-overlay { position: fixed; inset: 0; z-index: 10050; width: 100%; max-width: none; padding: clamp(14px, 4vw, 44px); background: radial-gradient(circle at 50% 20%, var(--cm-accent-medium), transparent 30rem), color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(18px) saturate(.8); }
.welcome-scene-overlay.leaving { opacity: 0; transform: scale(1.015); transition: opacity 260ms ease, transform 260ms ease; }
.scene-progress { display: flex; flex-wrap: wrap; gap: 12px; }
.scene-progress .scene-step { flex: 0 0 auto; }

@media (max-width: 560px) {
  .mobile-back-button { display: inline-grid; }
  .sync-status { padding-inline: 9px; }
  .sync-status strong { max-width: 64px; overflow: hidden; text-overflow: ellipsis; }
  .showcase-brand { position: relative; inset: auto; }
  .composer-input-wrap { min-height: 44px; height: 44px; }
  .composer-input-wrap #messageInput { height: 42px; min-height: 42px; }
  .message-delivery { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .welcome-scene-overlay.leaving { transition: none; }
}

/* CatMat cinematic experience ----------------------------------------- */
.email-change-box { display: grid; gap: 10px; margin: 4px 0; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--panel-2) 72%, transparent); }
.email-change-box legend { padding: 0 6px; color: var(--soft); font-size: 12px; font-weight: 800; }
.email-change-box small { color: var(--muted); line-height: 1.45; }
.profile-links { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.profile-links a { max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--accent); background: var(--panel-2); font-size: 12px; font-weight: 800; }
.moderator-audit { display: grid; gap: 9px; margin-top: 16px; padding: 12px; border: 1px solid color-mix(in srgb, #f59e0b 45%, var(--line)); border-radius: 14px; background: color-mix(in srgb, #f59e0b 9%, var(--panel)); }
.moderator-audit > strong { color: var(--text); font-size: 13px; }
.moderator-audit > small, .moderator-audit > span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.device-session-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.device-session-list li { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.device-session-list span { display: grid; min-width: 0; gap: 2px; }
.device-session-list b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.device-session-list small { color: var(--muted); font-size: 10px; }
.device-session-list button { flex: 0 0 auto; padding: 6px 8px; font-size: 11px; }
.support-settings p { margin: -2px 0 4px; color: var(--muted); font-size: 12px; line-height: 1.45; }
:is(.icon-button, .tool-button, .tiny-button, .rail-icon, #messageSend)[data-icon] {
  display: inline-grid !important;
  place-items: center !important;
  align-content: center;
  justify-content: center;
  padding: 0;
  line-height: 0;
  text-indent: 0;
}
:is(.icon-button, .tool-button, .tiny-button, .rail-icon, #messageSend)[data-icon]::before {
  display: block;
  flex: 0 0 auto;
  margin: 0;
  transform-origin: 50% 50%;
}

.setting-hint {
  display: block;
  margin-top: -4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.app-icon-preview {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  min-height: 72px;
  padding: 9px;
  border: 1px solid var(--cm-line-soft);
  border-radius: var(--cm-radius-md);
  background: var(--cm-surface-soft);
}
.app-icon-preview strong,
.app-icon-preview small { display: block; }
.app-icon-preview small { margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.custom-icon-upload input { width: 100%; min-height: 42px; padding: 8px; color: var(--muted); font-size: 11px; }
.custom-icon-upload input::file-selector-button { min-height: 30px; margin-right: 9px; padding: 0 10px; border: 1px solid var(--cm-line-soft); border-radius: 10px; background: var(--cm-surface-raised); color: var(--text); font-weight: 800; cursor: pointer; }
.app-icon-swatch {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--cm-line-strong);
  border-radius: 16px;
  background: #090b14;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .13);
  transition: background 260ms ease, border-radius 260ms ease, transform 340ms var(--cm-ease-spring);
}
.app-icon-swatch img { width: 40px; height: 40px; object-fit: contain; transition: filter 260ms ease, transform 340ms var(--cm-ease-spring); }
.app-icon-swatch[data-app-icon-preview="aurora"] { background: radial-gradient(circle at 28% 20%, #67e8f9, transparent 42%), linear-gradient(145deg, #7c3aed, #17112d); }
.app-icon-swatch[data-app-icon-preview="aurora"] img { filter: drop-shadow(0 8px 12px rgba(0,0,0,.38)) saturate(1.25); transform: rotate(-4deg) scale(1.05); }
.app-icon-swatch[data-app-icon-preview="midnight"] { background: radial-gradient(circle at 50% 15%, #28355f, #050713 68%); border-radius: 50%; }
.app-icon-swatch[data-app-icon-preview="midnight"] img { filter: grayscale(.25) hue-rotate(20deg) brightness(.9); transform: scale(.92); }
.app-icon-swatch[data-app-icon-preview="mono"] { background: #f5f5f5; border-radius: 12px; }
.app-icon-swatch[data-app-icon-preview="mono"] img { filter: grayscale(1) contrast(1.25); }

.settings-transition {
  position: fixed;
  inset: 0;
  z-index: 11000;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: all;
  isolation: isolate;
}
.settings-transition::before,
.settings-transition::after {
  content: "";
  position: absolute;
  width: 42vmax;
  height: 42vmax;
  border-radius: 42% 58% 62% 38% / 48% 44% 56% 52%;
  background: color-mix(in srgb, var(--accent) 88%, #11152a);
  box-shadow: 0 0 0 26vmax color-mix(in srgb, var(--bg) 78%, var(--accent));
  animation: cmInkBloom 720ms var(--cm-ease-standard) both;
}
.settings-transition::after {
  width: 24vmax;
  height: 24vmax;
  background: color-mix(in srgb, var(--cyan) 30%, var(--accent));
  opacity: .5;
  animation-delay: 70ms;
  animation-direction: reverse;
}
.settings-transition-gear {
  position: relative;
  z-index: 2;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 28px;
  background: rgba(8,10,20,.56);
  color: #fff;
  box-shadow: 0 20px 70px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.2);
  backdrop-filter: blur(18px);
  animation: cmGearReveal 760ms var(--cm-ease-spring) both;
}
.settings-transition-gear::before { width: 42px; height: 42px; animation: cmGearSpin 720ms cubic-bezier(.2,.8,.2,1) both; }
.settings-transition.leaving { animation: cmInkLeave 300ms ease both; }
.sidebar-view.settings-reveal.active { animation: cmSettingsReveal 540ms var(--cm-ease-spring) both; }
.settings-gear-spinning::before { animation: cmGearSpin 680ms var(--cm-ease-spring) both; }

.scene-card-pro {
  min-height: min(520px, calc(100dvh - 110px));
  grid-template-columns: minmax(0, .9fr) minmax(320px, 1.1fr);
  grid-template-areas: "copy visual" "progress visual" "actions visual";
  align-content: center;
  column-gap: clamp(28px, 6vw, 72px);
}
.scene-copy { grid-area: copy; display: grid; gap: 15px; }
.scene-card-pro .scene-progress { grid-area: progress; }
.scene-card-pro .scene-actions { grid-area: actions; }
.scene-visual {
  grid-area: visual;
  position: relative;
  min-height: 330px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--text) 14%, transparent);
  border-radius: clamp(24px, 4vw, 40px);
  background:
    radial-gradient(circle at 74% 20%, var(--cm-accent-medium), transparent 11rem),
    linear-gradient(155deg, color-mix(in srgb, var(--panel-2) 80%, transparent), color-mix(in srgb, var(--bg) 94%, transparent));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 10%, transparent), 0 32px 80px rgba(0,0,0,.22);
}
.scene-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(color-mix(in srgb, var(--text) 4%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--text) 4%, transparent) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, black, transparent 84%);
}
.scene-orb { position: absolute; border-radius: 50%; filter: blur(1px); animation: cmSceneFloat 4s ease-in-out infinite; }
.scene-orb.one { width: 72px; height: 72px; right: 12%; top: 12%; background: color-mix(in srgb, var(--cyan) 46%, transparent); }
.scene-orb.two { width: 38px; height: 38px; left: 13%; top: 20%; background: color-mix(in srgb, var(--accent) 62%, transparent); animation-delay: -1.4s; }
.scene-ground { position: absolute; left: 8%; right: 8%; bottom: 56px; height: 2px; background: linear-gradient(90deg, transparent, var(--cm-line-strong), transparent); }
.scene-runner {
  --runner-x: 36px;
  position: absolute;
  left: var(--runner-x);
  bottom: 58px;
  width: 46px;
  height: 92px;
  animation: cmRunnerTravel 3.6s var(--cm-ease-standard) infinite;
}
.scene-runner-head { position: absolute; left: 10px; top: 0; width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(145deg, #fed7aa, #fb7185); box-shadow: inset -5px -4px 0 rgba(0,0,0,.1); }
.scene-runner-body { position: absolute; left: 8px; top: 30px; width: 31px; height: 38px; border-radius: 13px 13px 9px 9px; background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #111827)); }
.scene-runner-arm,
.scene-runner-leg { position: absolute; width: 9px; border-radius: 99px; transform-origin: top center; }
.scene-runner-arm { top: 35px; height: 34px; background: #fda4af; animation: cmRunnerLimb 420ms ease-in-out infinite alternate; }
.scene-runner-arm.left { left: 5px; }
.scene-runner-arm.right { right: 3px; animation-direction: alternate-reverse; }
.scene-runner-leg { top: 65px; height: 28px; background: #7dd3fc; animation: cmRunnerLimb 420ms ease-in-out infinite alternate-reverse; }
.scene-runner-leg.left { left: 11px; }
.scene-runner-leg.right { right: 8px; animation-direction: alternate; }
.scene-portal { position: absolute; right: 11%; bottom: 55px; width: 82px; height: 150px; border: 3px solid color-mix(in srgb, var(--accent) 72%, #fff); border-radius: 48% 48% 12px 12px; box-shadow: 0 0 35px var(--cm-accent-medium), inset 0 0 28px var(--cm-accent-soft); animation: cmPortalPulse 1.8s ease-in-out infinite; }
.scene-message-pod { position: absolute; right: 16%; top: 27%; min-width: 118px; padding: 12px 15px; border: 1px solid rgba(255,255,255,.28); border-radius: 18px 18px 7px 18px; background: linear-gradient(135deg, var(--accent), #6d5dfc); color: #fff; font-size: 12px; font-weight: 850; box-shadow: 0 16px 38px var(--cm-accent-medium); animation: cmMessagePod 3.6s var(--cm-ease-standard) infinite; }
.scene-message-pod::after { content: "✓"; float: right; margin-left: 9px; }
.scene-network-node { position: absolute; width: 70px; height: 70px; display: grid; place-items: center; border: 1px solid var(--cm-line-strong); border-radius: 22px; background: var(--cm-glass-strong); color: var(--accent); box-shadow: var(--cm-shadow-md); animation: cmSceneFloat 3.4s ease-in-out infinite; }
.scene-network-node::before { width: 30px; height: 30px; }
.scene-network-node.chat { left: 12%; top: 18%; }
.scene-network-node.call { right: 12%; top: 21%; animation-delay: -.8s; }
.scene-network-node.share { left: 34%; bottom: 12%; animation-delay: -1.6s; }
.scene-network-line { position: absolute; left: 27%; right: 25%; top: 48%; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), var(--cyan), transparent); box-shadow: 0 0 18px var(--cm-accent-medium); animation: cmNetworkFlow 1.8s linear infinite; }
.scene-theme-gear { position: absolute; left: 50%; top: 50%; width: 108px; height: 108px; display: grid; place-items: center; border: 1px solid var(--cm-line-strong); border-radius: 34px; background: var(--cm-glass-strong); color: var(--accent); transform: translate(-50%, -50%); box-shadow: var(--cm-shadow-lg); }
.scene-theme-gear::before { width: 54px; height: 54px; animation: cmGearSpin 5s linear infinite; }
.scene-theme-wave { position: absolute; inset: 50% auto auto 50%; width: 40px; height: 40px; border: 2px solid var(--accent); border-radius: 50%; transform: translate(-50%, -50%); animation: cmThemeRipple 2.2s ease-out infinite; }
.scene-swipe-hint { flex: 1 0 100%; color: var(--muted); font-size: 10px; line-height: 1.4; text-align: left; opacity: .78; }
.welcome-scene-overlay.scene-changing .scene-card { animation: cmSceneSlideOut 230ms ease both; }
.scene-card.scene-enter-forward { animation: cmSceneSlideInRight 460ms var(--cm-ease-spring) both; }
.scene-card.scene-enter-back { animation: cmSceneSlideInLeft 460ms var(--cm-ease-spring) both; }

@keyframes cmInkBloom { 0% { opacity: 0; transform: scale(.04) rotate(-20deg); } 70% { opacity: 1; } 100% { opacity: 1; transform: scale(3.6) rotate(28deg); } }
@keyframes cmInkLeave { to { opacity: 0; filter: blur(12px); } }
@keyframes cmGearReveal { 0% { opacity: 0; transform: scale(.5) rotate(-70deg); } 55% { opacity: 1; transform: scale(1.08) rotate(8deg); } 100% { transform: none; } }
@keyframes cmGearSpin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
@keyframes cmSettingsReveal { 0% { opacity: 0; transform: translateX(16px) scale(.98); filter: blur(7px); } 100% { opacity: 1; transform: none; filter: none; } }
@keyframes cmSceneFloat { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
@keyframes cmRunnerTravel { 0% { transform: translateX(0); } 58% { transform: translateX(150px); } 72% { transform: translateX(150px) scale(.92); opacity: 1; } 82% { transform: translateX(178px) scale(.65); opacity: 0; } 83% { transform: translateX(0); opacity: 0; } 100% { opacity: 1; } }
@keyframes cmRunnerLimb { from { transform: rotate(-25deg); } to { transform: rotate(25deg); } }
@keyframes cmPortalPulse { 0%,100% { transform: scale(1); filter: brightness(.95); } 50% { transform: scale(1.035); filter: brightness(1.25); } }
@keyframes cmMessagePod { 0%,38% { opacity: 0; transform: translate(30px, 18px) scale(.75); } 52%,88% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-12px); } }
@keyframes cmNetworkFlow { to { filter: hue-rotate(90deg); background-position: 150px 0; } }
@keyframes cmThemeRipple { 0% { opacity: .75; transform: translate(-50%, -50%) scale(.45); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(7); } }
@keyframes cmSceneSlideOut { to { opacity: 0; transform: translateX(-46px) scale(.985); filter: blur(7px); } }
@keyframes cmSceneSlideInRight { from { opacity: 0; transform: translateX(54px) scale(.985); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes cmSceneSlideInLeft { from { opacity: 0; transform: translateX(-54px) scale(.985); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }

@media (max-width: 760px) {
  .scene-card-pro { grid-template-columns: 1fr; grid-template-areas: "visual" "copy" "progress" "actions"; min-height: 0; }
  .scene-visual { min-height: 230px; }
  .scene-runner { transform: scale(.82); transform-origin: bottom left; }
  .scene-card-pro .scene-copy { gap: 10px; }
}

@media (max-width: 560px) {
  body { padding: 0; background: var(--bg); }
  .rail {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(5px, env(safe-area-inset-left));
  }
  .rail-icon { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .sidebar-header {
    min-height: calc(68px + env(safe-area-inset-top));
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .profile-footer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .chat-header { padding-right: max(10px, env(safe-area-inset-right)); }
  .message-form { margin-right: max(8px, env(safe-area-inset-right)); }
  .welcome-scene-overlay { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .scene-card-pro { max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px); overflow: auto; padding: 18px; gap: 12px; }
  .scene-visual { min-height: 190px; }
  .scene-card-pro h1 { font-size: clamp(27px, 9vw, 38px); }
  .scene-message-pod { min-width: 98px; right: 8%; }
  .scene-portal { right: 7%; height: 115px; }
  .scene-runner { bottom: 51px; }
  .settings-transition-gear { width: 74px; height: 74px; border-radius: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .settings-transition::before,
  .settings-transition::after,
  .settings-transition-gear,
  .settings-transition-gear::before,
  .scene-runner,
  .scene-runner-arm,
  .scene-runner-leg,
  .scene-message-pod,
  .scene-portal,
  .scene-orb,
  .scene-network-node,
  .scene-network-line,
  .scene-theme-gear::before,
  .scene-theme-wave { animation: none !important; }
}
