:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-deep: #e9edf4;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.62);
  --text: #111827;
  --muted: #6b7280;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.16);
  --primary: #007aff;
  --primary-dark: #0064d2;
  --danger: #ff3b30;
  --success: #34c759;
  --mine: #eaf4ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 70px rgba(17, 24, 39, 0.16);
  --soft-shadow: 0 12px 30px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 0%, rgba(0, 122, 255, 0.16), transparent 34%),
    linear-gradient(135deg, #f7f8fb 0%, var(--bg-deep) 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(0, 122, 255, 0.2);
  outline-offset: 2px;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 34px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.auth-kicker {
  margin: 0 0 10px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 34px;
  line-height: 1.05;
}

.muted,
.auth-link,
.hint {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 26px;
}

.auth-form label {
  font-size: 14px;
  font-weight: 650;
}

.auth-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.auth-form input {
  height: 48px;
  padding: 0 14px;
}

.auth-form input:focus,
.composer textarea:focus {
  border-color: rgba(0, 122, 255, 0.58);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.12);
}

.auth-form button,
.composer-actions button,
.room-button,
.secondary-button {
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(0, 122, 255, 0.22);
}

.auth-form button:hover,
.composer-actions button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  box-shadow: none;
}

.form-message {
  min-height: 22px;
  margin: 6px 0 0;
}

.success {
  color: #167a38;
}

.error,
.error-text {
  color: var(--danger);
}

.chat-page {
  padding: 18px;
  overflow: hidden;
}

.chat-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: min(1220px, 100%);
  height: calc(100vh - 36px);
  margin: 0 auto;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.chat-shell.shake {
  animation: shake-window 0.42s ease-in-out;
}

@keyframes shake-window {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-8px); }
  30%, 60%, 90% { transform: translateX(8px); }
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  min-height: 0;
  padding: 20px;
  background: rgba(247, 248, 252, 0.78);
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  column-gap: 12px;
  align-items: center;
}

.app-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: #ffffff;
  background: linear-gradient(145deg, #111827, #3b82f6);
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--soft-shadow);
}

.brand h1,
.chat-header h2,
.online-section h2 {
  margin: 0;
}

.brand h1 {
  font-size: 21px;
}

.brand p,
.eyebrow,
.status-message {
  margin: 4px 0 0;
  color: var(--muted);
}

.brand p {
  grid-column: 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-button {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  box-shadow: none;
  text-align: left;
}

.room-button.active {
  color: #ffffff;
  background: var(--primary);
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(0, 122, 255, 0.24);
}

.online-section {
  min-height: 0;
  flex: 1;
}

.online-section h2,
.banned-section h2 {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
}

.banned-section {
  display: grid;
  gap: 8px;
  max-height: 190px;
  min-height: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-title-row h2 {
  margin: 0;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
}

.user-list {
  display: grid;
  gap: 8px;
  max-height: 100%;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.user-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.user-button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  text-align: left;
}

.user-button:hover,
.small-button:hover,
.secondary-button:hover,
.emoji-bar button:hover {
  background: #ffffff;
  border-color: var(--line-strong);
}

.user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-list li.selected .user-button {
  border-color: rgba(0, 122, 255, 0.34);
  background: var(--mine);
}

.online-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.13);
}

.online-dot.offline {
  background: #a1a1aa;
  box-shadow: none;
}

.badge,
.private-badge,
.read-status,
.unread-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  color: #8a4b00;
  background: #fff1d6;
}

.private-badge {
  color: #0050a4;
  background: #e6f2ff;
}

.read-status {
  color: #5f6673;
  background: #f0f2f5;
}

.unread-badge {
  margin-left: auto;
  color: #ffffff;
  background: var(--danger);
}

.ban-button,
.unban-button,
.message-delete,
.icon-button {
  min-height: 34px;
  border: 1px solid rgba(255, 59, 48, 0.24);
  border-radius: var(--radius-sm);
  color: var(--danger);
  background: rgba(255, 59, 48, 0.07);
}

.unban-button {
  border-color: rgba(52, 199, 89, 0.28);
  color: #167a38;
  background: rgba(52, 199, 89, 0.08);
}

.banned-user {
  display: grid;
  min-width: 0;
}

.banned-user small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 14px;
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.62);
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  font-size: 23px;
  line-height: 1.1;
}

.eyebrow {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-message {
  max-width: 38ch;
  text-align: right;
}

.messages-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: rgba(250, 251, 253, 0.58);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
  padding: 24px 24px 96px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb {
  background: rgba(107, 114, 128, 0.32);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.message {
  width: min(680px, 92%);
  padding: 12px 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 18px 18px 18px 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.05);
}

.empty-state {
  width: min(520px, 100%);
  margin: auto;
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
}

.system-notice {
  align-self: center;
  max-width: min(520px, 92%);
  padding: 8px 14px;
  border: 1px solid rgba(0, 122, 255, 0.16);
  border-radius: 999px;
  color: #0050a4;
  background: rgba(230, 242, 255, 0.82);
  font-size: 14px;
  text-align: center;
}

.message.mine {
  align-self: flex-end;
  border-radius: 18px 18px 6px 18px;
  background: var(--mine);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.message-meta strong {
  color: var(--text);
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
}

.message-image {
  display: block;
  width: min(420px, 100%);
  max-height: 360px;
  object-fit: contain;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  background: #111827;
}

.message-delete {
  margin-top: 10px;
  padding: 0 10px;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 12px 14px 14px;
  background: rgba(255, 255, 255, 0.84);
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 30px rgba(17, 24, 39, 0.06);
  backdrop-filter: blur(20px);
}

.emoji-bar {
  display: flex;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--soft-shadow);
}

.emoji-bar.hidden {
  display: none;
}

.emoji-bar button,
.composer-icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: none;
}

.composer-icon-button {
  flex: 0 0 auto;
  font-size: 22px;
  font-weight: 500;
}

.composer-icon-button:hover,
.emoji-bar button:hover {
  color: var(--primary);
  background: #ffffff;
  border-color: rgba(0, 122, 255, 0.24);
}

.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer textarea {
  min-height: 40px;
  max-height: 132px;
  padding: 10px 13px;
  resize: none;
  overflow-y: auto;
  border-radius: 20px;
}

.send-button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(0, 122, 255, 0.22);
}

.send-button:hover {
  background: var(--primary-dark);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 48px;
}

.hint {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paste-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid rgba(0, 122, 255, 0.26);
  border-radius: var(--radius-sm);
  background: rgba(230, 242, 255, 0.78);
}

.paste-preview img {
  width: 72px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
}

.paste-preview p {
  margin: 4px 0 0;
  color: var(--muted);
}

.hidden {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.sidebar-overlay,
.header-icon-button {
  display: none;
}

.new-messages-button {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid rgba(0, 122, 255, 0.22);
  border-radius: 999px;
  color: #0050a4;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 26px rgba(0, 122, 255, 0.18);
  transform: translateX(-50%);
}

.new-messages-button:hover {
  transform: translateX(-50%) translateY(-1px);
}

@media (max-width: 860px) {
  .chat-page {
    padding: 0;
    overflow: hidden;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    border: 0;
    border-radius: 0;
    background: rgba(17, 24, 39, 0.22);
    backdrop-filter: blur(6px);
  }

  .sidebar-overlay.hidden {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 30;
    width: min(326px, calc(100vw - 28px));
    display: flex;
    max-height: none;
    padding: 16px;
    gap: 10px;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 24px;
    box-shadow: var(--shadow);
    transform: translateX(calc(-100% - 24px));
    transition: transform 220ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .room-button,
  .secondary-button {
    width: 100%;
    min-height: 40px;
  }

  .online-section {
    min-height: 0;
    max-height: none;
  }

  .user-list {
    display: grid;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .user-list li {
    width: auto;
  }

  .banned-section {
    max-height: 130px;
  }

  .chat-header {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    min-height: 70px;
    padding: 14px;
    align-items: center;
    gap: 6px;
  }

  .header-icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.78);
    box-shadow: none;
  }

  .status-message {
    grid-column: 1 / -1;
    max-width: none;
    text-align: left;
  }

  .messages {
    padding: 14px 14px 92px;
  }

  .message {
    width: min(620px, 96%);
  }

  .composer-actions {
    padding: 0 4px;
  }

  .composer-bar {
    gap: 6px;
  }

  .composer-icon-button {
    width: 38px;
    height: 38px;
  }

  .send-button {
    min-width: 76px;
    padding: 0 12px;
  }

  .hint {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  .auth-page {
    padding: 14px;
  }

  .auth-card {
    padding: 26px 20px;
    border-radius: 22px;
  }

  .auth-card h1 {
    font-size: 30px;
  }

  .sidebar {
    top: 8px;
    bottom: 8px;
    left: 8px;
    width: min(318px, calc(100vw - 20px));
  }

  .emoji-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .paste-preview {
    align-items: flex-start;
  }
}
