:root {
  color-scheme: dark;
  --page: #11151b;
  --panel: #191f27;
  --raised: #202832;
  --line: #2a3440;
  --text: #eef3f8;
  --muted: #8d9aa9;
  --accent: #7daeff;
  --red: #ff6868;
  --gold: #f2bd58;
  --green: #5acb91;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--page); color: var(--text); }
button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(ellipse at 50% 20%, #1c2a3b, transparent 52%), var(--page); }
.auth-card { width: min(100%, 390px); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: 0 22px 80px #0005; }
.brand-mark { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 14px; background: linear-gradient(135deg, #78aaff, #9c83ff); color: #101522; font-size: 22px; font-weight: 800; }
.auth-card h1 { margin: 18px 0 2px; font-size: 28px; letter-spacing: -.04em; }
.auth-card > p { margin: 0; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 28px 0 22px; padding: 4px; border-radius: 10px; background: var(--page); }
.tab { padding: 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--raised); color: var(--text); }
#auth-form { display: grid; gap: 9px; }
#auth-form label { margin-top: 7px; font-size: 13px; font-weight: 650; }
#auth-form input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 9px; outline: none; background: #11161d; color: var(--text); }
#auth-form input:focus, textarea:focus { border-color: var(--accent); }
.field-hint { margin: 0 0 5px; color: var(--muted); font-size: 12px; }
.primary-button { padding: 12px; border: 0; border-radius: 9px; background: var(--accent); color: #101725; font-weight: 750; cursor: pointer; }
.primary-button:disabled, .send-button:disabled { cursor: not-allowed; opacity: .45; }
.error-message { margin: 14px 0 0; color: #ff8c8c; font-size: 13px; }

.chat-layout { display: grid; min-height: 100vh; grid-template-columns: 245px minmax(0, 1fr); }
.chat-layout.with-admin { grid-template-columns: 225px minmax(0, 1fr) 300px; }
.sidebar, .admin-panel { display: flex; min-height: 100vh; flex-direction: column; background: var(--panel); }
.sidebar { padding: 22px 15px 14px; border-right: 1px solid var(--line); }
.sidebar-heading { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }
.sidebar-heading div:last-child { display: grid; gap: 2px; }
.sidebar-heading strong { font-size: 15px; }
.sidebar-heading .muted { font-size: 11px; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 17px; }
.room-label, .section-title, .admin-kicker, .ban-heading { color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .1em; }
.room-label { padding: 0 10px 9px; }
.room-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; background: #293444; font-size: 13px; font-weight: 650; }
.room-dot, .online-indicator { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--green); }
.people-section { min-height: 0; flex: 1; padding-top: 30px; }
.section-title { display: flex; justify-content: space-between; padding: 0 8px 10px; }
.count-pill { min-width: 20px; padding: 1px 5px; border-radius: 10px; background: var(--raised); text-align: center; letter-spacing: 0; }
.people-list, .admin-users, .admin-bans { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.people-list li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 7px; color: #dbe3ec; font-size: 12px; overflow-wrap: anywhere; }
.people-list li::before { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--green); content: ""; }
.people-list .admin-name, .message-name.admin-name { color: var(--red); }
.people-list .vip-name, .message-name.vip-name { color: var(--gold); }
.role-tag { padding: 2px 5px; border: 1px solid currentColor; border-radius: 5px; font-size: 8px; font-weight: 800; letter-spacing: .05em; }
.account-box { display: flex; align-items: center; gap: 9px; min-height: 49px; padding: 7px 8px; border-top: 1px solid var(--line); }
.account-name { flex: 1; overflow: hidden; font-size: 12px; font-weight: 650; text-overflow: ellipsis; }
.icon-button { display: grid; width: 31px; height: 31px; place-items: center; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.icon-button:hover { border-color: var(--line); background: var(--raised); color: var(--text); }

.conversation { display: flex; height: 100vh; min-width: 0; flex-direction: column; }
.chat-header { display: flex; min-height: 75px; align-items: center; justify-content: space-between; padding: 13px 24px; border-bottom: 1px solid var(--line); }
.header-actions, .admin-header-actions { display: flex; align-items: center; gap: 9px; }
.admin-toggle { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--raised); color: var(--text); cursor: pointer; font-size: 11px; }
.admin-toggle:hover { border-color: var(--red); }
.close-admin { display: none; }
.chat-header h2 { margin: 0 0 4px; font-size: 15px; }
.chat-header p { display: flex; align-items: center; gap: 7px; margin: 0; color: var(--muted); font-size: 11px; }
.chat-header p .room-dot { width: 6px; height: 6px; }
.connection-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection-state span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.connection-state.connected span { background: var(--green); }
.connection-state.disconnected span { background: var(--red); }
.notice { padding: 9px 20px; border-bottom: 1px solid var(--line); color: var(--muted); text-align: center; font-size: 12px; }
.messages { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 18px; overflow-y: auto; margin: 0; padding: 25px clamp(18px, 5vw, 70px); list-style: none; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; animation: arrive .14s ease-out; }
@keyframes arrive { from { transform: translateY(4px); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
.avatar { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid #ffffff13; border-radius: 11px; background: var(--raised); color: var(--accent); font-size: 13px; font-weight: 750; }
.avatar.admin-name { background: #582b32; color: var(--red); }
.avatar.vip-name { background: #493b25; color: var(--gold); }
.message-meta { display: flex; align-items: baseline; gap: 8px; margin: 1px 0 4px; }
.message-name { font-size: 12px; font-weight: 750; }
.message-time { color: var(--muted); font-size: 10px; }
.message-text { margin: 0; color: #d7dfe8; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }
.system-message { align-self: center; color: var(--muted); font-size: 11px; }
.composer { padding: 12px clamp(16px, 5vw, 70px) 14px; border-top: 1px solid var(--line); }
.composer-row { display: flex; align-items: flex-end; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.composer textarea { width: 100%; max-height: 140px; resize: vertical; padding: 6px; border: 1px solid transparent; outline: none; background: transparent; color: var(--text); font-size: 13px; line-height: 1.45; }
.composer textarea::placeholder { color: #748292; }
.send-button { display: grid; width: 34px; height: 34px; flex: none; place-items: center; border: 0; border-radius: 9px; background: var(--accent); color: #111723; cursor: pointer; font-size: 21px; font-weight: 800; }
.composer-foot { display: flex; justify-content: space-between; padding: 7px 3px 0; color: var(--muted); font-size: 10px; }
.mute-notice { margin: 0 0 9px; padding: 10px 12px; border: 1px solid #713b3b; border-radius: 9px; background: #311e23; color: #ff9a9a; font-size: 12px; }
.mute-notice strong { color: #ff7777; }

.admin-panel { gap: 0; overflow-y: auto; padding: 20px 15px; border-left: 1px solid var(--line); }
.admin-header { display: flex; align-items: center; justify-content: space-between; }
.admin-kicker { color: var(--red); }
.admin-header h2 { margin: 4px 0 0; font-size: 16px; }
.admin-caption { margin: 8px 0 16px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.admin-users li { padding: 10px 0; border-top: 1px solid var(--line); }
.admin-user-row { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.admin-user-name { overflow: hidden; font-size: 12px; font-weight: 700; text-overflow: ellipsis; }
.admin-user-ip { margin-top: 4px; color: var(--muted); font-family: ui-monospace, monospace; font-size: 10px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.admin-actions button, .admin-bans button { padding: 4px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: #c6d0dc; cursor: pointer; font-size: 10px; }
.admin-actions button:hover, .admin-bans button:hover { border-color: var(--accent); color: var(--text); }
.admin-actions button.danger { color: #ff9797; }
.ban-heading { margin: 18px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.admin-bans li { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 0; color: #e2b2b2; font-family: ui-monospace, monospace; font-size: 10px; overflow-wrap: anywhere; }
.empty-state { padding: 16px 8px; color: var(--muted); font-size: 11px; }

@media (prefers-color-scheme: light) {
  :root { color-scheme: light; --page: #f2f5f8; --panel: #fff; --raised: #edf1f6; --line: #dbe2ea; --text: #1b2633; --muted: #697888; }
  .auth-card { background: #ffffffed; box-shadow: 0 22px 80px #16314b19; }
  .auth-shell { background: radial-gradient(ellipse at 50% 20%, #dfeaff, transparent 52%), var(--page); }
  #auth-form input { background: #f8fafc; color: var(--text); }
  .room-item { background: #e8eff9; }
  .people-list li, .message-text { color: #354253; }
  .avatar.admin-name { background: #ffe5e5; }
  .avatar.vip-name { background: #fff0d1; }
  .mute-notice { background: #fff1f1; color: #9c2929; }
}

@media (max-width: 850px) {
  .chat-layout, .chat-layout.with-admin { grid-template-columns: 200px minmax(0, 1fr); }
  .admin-panel { position: fixed; z-index: 3; top: 0; right: 0; width: min(320px, 90vw); height: 100vh; box-shadow: -12px 0 35px #0006; }
  .close-admin { display: grid; }
}
@media (max-width: 600px) {
  .chat-layout, .chat-layout.with-admin { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .conversation { height: 100dvh; }
  .chat-header { min-height: 65px; padding: 10px 16px; }
  .messages { padding: 20px 15px; }
  .composer { padding: 10px 12px; }
  .composer-foot span:last-child { display: none; }
}
