:root {
  --bg-0: #0c1020;
  --bg-1: rgba(18, 23, 42, 0.88);
  --bg-2: rgba(13, 17, 31, 0.84);
  --bg-3: rgba(255, 255, 255, 0.08);
  --bg-4: #090c18;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef3ff;
  --muted: #b5c0de;
  --muted-soft: #8490b4;
  --accent: #5b7cff;
  --accent-2: #19c5b1;
  --accent-3: #ff6f91;
  --green: #29d08a;
  --danger: #ff5b72;
  --shadow: 0 28px 70px rgba(4, 8, 22, 0.36);
  --surface-glow:
    radial-gradient(circle at top left, rgba(91, 124, 255, 0.2), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 111, 145, 0.14), transparent 24%);
}

:root[data-theme="light"] {
  --bg-0: #edf4ff;
  --bg-1: rgba(255, 255, 255, 0.84);
  --bg-2: rgba(245, 249, 255, 0.9);
  --bg-3: rgba(57, 83, 145, 0.08);
  --bg-4: #dde9ff;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(91, 124, 255, 0.1);
  --line: rgba(57, 83, 145, 0.12);
  --text: #1b2645;
  --muted: #54627f;
  --muted-soft: #7081a6;
  --accent: #4167ff;
  --accent-2: #09b9a8;
  --accent-3: #ff5f89;
  --green: #14ad73;
  --danger: #dc4d64;
  --shadow: 0 24px 60px rgba(76, 108, 176, 0.18);
  --surface-glow:
    radial-gradient(circle at top left, rgba(65, 103, 255, 0.15), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 95, 137, 0.12), transparent 24%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  background:
    var(--surface-glow),
    linear-gradient(160deg, var(--bg-0), #12182d 72%);
  color: var(--text);
  overflow: hidden;
  transition: background 260ms ease, color 220ms ease;
}

body.auth-locked {
  overflow: hidden;
}

:root[data-theme="light"] body {
  background:
    var(--surface-glow),
    linear-gradient(160deg, #eff5ff, #e6efff 72%);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-3));
  border-radius: 999px;
}

button,
input {
  font: inherit;
}

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

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

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 78px 340px 1fr 280px;
  overflow: hidden;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-gate__panel {
  width: min(100%, 1040px);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 22px;
  align-items: stretch;
}

.auth-gate__brand,
.auth-panel--gate {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.auth-gate__brand {
  padding: 34px;
  display: grid;
  align-content: center;
  gap: 12px;
}

.auth-gate__brand h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  line-height: 0.95;
}

.auth-gate__copy {
  max-width: 34ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 1rem;
}

.auth-panel--gate {
  padding: 20px;
}

.server-rail,
.channel-sidebar,
.chat-main,
.members-sidebar {
  min-height: 0;
}

.server-rail {
  padding: 18px 0;
  background: rgba(9, 12, 24, 0.84);
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 14px;
}

.server-badge {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.server-badge.active,
.server-badge:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: white;
}

.channel-sidebar,
.members-sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
}

@supports ((-webkit-backdrop-filter: blur(16px)) or (backdrop-filter: blur(16px))) {
  .server-rail {
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
  }

  .channel-sidebar,
  .members-sidebar {
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
  }
}

.channel-sidebar {
  padding: 22px 18px;
  display: grid;
  align-content: start;
  gap: 18px;
  overflow: auto;
}

.workspace-header,
.chat-header,
.members-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.workspace-kicker,
.chat-subtitle {
  margin: 0;
  color: var(--muted-soft);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.workspace-header h1,
.chat-title-wrap h2,
.members-header h3 {
  margin: 6px 0 0;
}

.workspace-pill,
.presence-pill,
.theme-toggle {
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.82rem;
}

.workspace-pill,
.presence-pill {
  background: rgba(41, 208, 138, 0.12);
  color: var(--green);
}

.theme-toggle {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: white;
  box-shadow: 0 12px 24px rgba(91, 124, 255, 0.22);
}

.auth-panel,
.session-card,
.join-form,
.message,
.composer-wrap,
.members-sidebar .user-list {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-panel,
.session-card,
.join-form,
.composer-wrap,
.members-sidebar .user-list {
  border-radius: 22px;
}

.auth-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-tab,
.channel-chip,
.ghost-button,
.tool-button {
  border-radius: 14px;
  padding: 11px 13px;
  background: transparent;
  color: var(--muted);
}

.auth-tab.active,
.channel-chip.active,
.auth-tab:hover,
.channel-chip:hover,
.ghost-button:hover,
.tool-button:hover {
  background: var(--bg-3);
  color: var(--text);
}

.auth-form,
.join-form,
label,
.session-panel,
.sidebar-section {
  display: grid;
  gap: 10px;
}

label span,
.section-title,
.section-count {
  color: var(--muted-soft);
  font-size: 0.84rem;
  font-weight: 700;
}

input {
  width: 100%;
  padding: 13px 15px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: rgba(10, 12, 22, 0.34);
  color: var(--text);
  outline: none;
}

:root[data-theme="light"] input {
  background: rgba(255, 255, 255, 0.72);
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 124, 255, 0.14);
}

.auth-form button,
.join-form button,
.message-form button {
  border-radius: 14px;
  padding: 12px 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 800;
}

.feedback {
  min-height: 18px;
  margin: 0;
  color: var(--muted-soft);
  font-size: 0.82rem;
}

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

.feedback.success {
  color: var(--green);
}

.hidden {
  display: none;
}

.session-card {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

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

.channel-list {
  display: grid;
  gap: 8px;
}

.channel-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: flex-start;
}

.chat-main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg-2);
}

.chat-header {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-title-wrap {
  display: flex;
  gap: 12px;
  align-items: center;
}

.hash {
  color: var(--accent);
  font-size: 1.7rem;
  font-weight: 800;
}

.presence-pill {
  display: flex;
  align-items: center;
  gap: 8px;
}

.presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

.messages {
  overflow: auto;
  padding: 18px 22px;
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 8px;
  padding: 16px 18px;
  border-radius: 22px;
  transition: transform 180ms ease, background 180ms ease;
}

.message:hover {
  background: var(--panel-strong);
}

.log-message {
  border-left: 4px solid var(--accent-2);
}

.message-enter {
  animation: messageIn 260ms ease;
}

.message-meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.message-meta strong {
  font-weight: 800;
}

.message-meta span {
  color: var(--muted-soft);
  font-size: 0.78rem;
}

.message p {
  margin: 0;
  line-height: 1.65;
}

.message-actions,
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-button,
.reaction-pill,
.emoji-chip {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.84rem;
}

.icon-button.active,
.reaction-pill.active {
  background: rgba(91, 124, 255, 0.18);
  color: var(--accent);
}

.icon-button.danger {
  color: var(--danger);
}

.message a {
  color: var(--accent);
}

.media-card {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.chat-image,
.chat-video {
  width: min(100%, 460px);
  max-height: 340px;
  border-radius: 18px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.chat-audio {
  width: min(100%, 460px);
}

.composer-wrap {
  margin: 0 18px 18px;
  padding: 14px;
}

.typing-indicator {
  min-height: 20px;
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.88rem;
}


.tools-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 16px;
  background: var(--bg-3);
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tool-button,
.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  padding: 10px 13px;
  border-radius: 14px;
}

.tool-button.recording {
  background: linear-gradient(135deg, var(--danger), var(--accent-3));
  color: white;
}

.file-picker {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: white;
}

.emoji-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.message-form input {
  background: rgba(10, 12, 22, 0.12);
}

.members-sidebar {
  padding: 22px 16px;
  overflow: auto;
}

.members-sidebar .user-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.user-row,
.empty-state {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--muted);
}

.user-row:hover {
  background: var(--bg-3);
  color: var(--text);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  flex: 0 0 auto;
}

button:disabled,
input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 78px 340px 1fr;
  }

  .members-sidebar {
    display: none;
  }
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .auth-gate__panel {
    grid-template-columns: 1fr;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .server-rail,
  .members-sidebar {
    display: none;
  }
}

@media (max-width: 560px) {
  .chat-header {
    align-items: start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .message-form {
    grid-template-columns: 1fr;
  }
}
