:root {
  --bg: #101216;
  --panel: #1b1f26;
  --panel-soft: #202632;
  --text: #e7edf7;
  --muted: #95a0b3;
  --accent: #4cb86a;
  --danger: #d05f5f;
  --border: #2a3241;
}

html {
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top left, #1a2230 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

.view {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.auth-card {
  width: min(420px, 92vw);
  margin: 8vh auto;
  padding: 1.5rem;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
  margin: 0 0 0.2rem;
}

.auth-card p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn,
button {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

button:hover,
.tab-btn:hover {
  border-color: var(--accent);
}

.tab-btn.active {
  background: #2a3447;
  border-color: #3b4b64;
}

.auth-form {
  display: none;
  gap: 0.5rem;
}

.auth-form.active {
  display: grid;
}

input,
textarea,
select {
  background: #121620;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

.topbar {
  height: 58px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: rgba(16, 18, 22, 0.86);
  backdrop-filter: blur(6px);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

#latencyLabel {
  color: var(--muted);
}

#versionLabel {
  color: var(--muted);
}

.connection-ok {
  color: var(--accent);
}

.connection-bad {
  color: #ef7a7a;
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr minmax(320px, max-content);
  gap: 0.8rem;
  padding: 0.8rem;
  height: calc(100vh - 58px);
}

.panel {
  background: rgba(27, 31, 38, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.channels,
.members {
  padding: 0.8rem;
}

.channels {
  display: flex;
  flex-direction: column;
}

.channel-group {
  display: grid;
}

.channels h3,
.members h3 {
  color: var(--muted);
  margin: 0.6rem 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mini-btn {
  padding: 0.25rem 0.55rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.channel-item,
.voice-item,
.member-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.45rem;
  padding: 0.45rem 0.55rem;
}

.channel-item.active {
  border-color: var(--accent);
  background: #273227;
}

.voice-item .voice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.voice-title {
  font-size: 1rem;
  font-weight: 600;
}

.voice-participants {
  color: var(--muted);
}

.voice-participant-list {
  display: grid;
  gap: 0.32rem;
}

.voice-participant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.voice-participant.is-clickable {
  border-radius: 7px;
  padding: 0.18rem 0.28rem;
  cursor: pointer;
}

.voice-participant.is-clickable:hover {
  background: rgba(44, 56, 78, 0.45);
}

.voice-participant-main {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.voice-participant-name {
  font-size: 0.93rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-local-muted {
  color: #f2b15f;
  font-size: 0.85rem;
  line-height: 1;
}

.voice-status {
  color: #ef7a7a;
  font-size: 0.8rem;
  white-space: nowrap;
}

.user-avatar-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  background: #2f3646;
  border: 1px solid var(--border);
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat header {
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 0.9rem;
}

.chat h2 {
  margin: 0;
}

.messages {
  flex: 1;
  min-height: 0;
  padding: 0.8rem;
  overflow-y: auto;
  overflow-x: visible;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.message {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  background: rgba(17, 23, 31, 0.55);
  overflow: visible;
}

.message-content {
  min-width: 0;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2f3646;
  object-fit: cover;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.message-body a {
  color: #8fc8ff;
}

.message-body {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-meta-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.message-menu {
  position: relative;
  opacity: 0;
  pointer-events: none;
}

.pinned-item .message-menu {
  opacity: 1;
  pointer-events: auto;
}

.message:hover .message-menu,
.pinned-item:hover .message-menu,
.message-menu[open] {
  opacity: 1;
  pointer-events: auto;
}

.message-menu summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.1rem 0.45rem;
  color: var(--muted);
}

.message-menu summary::-webkit-details-marker {
  display: none;
}

.message-menu[open] summary {
  border-color: var(--accent);
  color: var(--text);
}

.message-menu-list {
  position: absolute;
  top: calc(100% + 0.35rem);
  bottom: auto;
  right: 0;
  min-width: 150px;
  max-width: min(260px, 70vw);
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171d28;
  display: grid;
  gap: 0.3rem;
  padding: 0.35rem;
  z-index: 6;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.message-menu.open-up .message-menu-list {
  top: auto;
  bottom: calc(100% + 0.35rem);
}

.message-menu-list button {
  text-align: left;
  padding: 0.35rem 0.5rem;
}

.message-menu-list .danger {
  border-color: #7b4040;
  color: #ffb3b3;
}

.message-image {
  margin-top: 0.4rem;
  max-width: min(360px, 100%);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.pinned-messages {
  border-bottom: 1px solid var(--border);
  background: rgba(23, 31, 42, 0.94);
  padding: 0.55rem 0.8rem;
  display: grid;
  gap: 0.45rem;
}

.pinned-title {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pinned-list {
  display: grid;
  gap: 0.35rem;
}

.pinned-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 20, 28, 0.84);
  padding: 0.42rem 0.5rem;
  font-size: 0.9rem;
  display: grid;
  gap: 0.35rem;
}

.pinned-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.pinned-item-header-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pinned-item-header strong {
  color: var(--text);
}

.pinned-item .poll-card {
  margin-top: 0;
}

.poll-card {
  margin-top: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  background: rgba(18, 24, 33, 0.9);
}

.poll-question {
  margin: 0 0 0.45rem;
  font-weight: 600;
}

.poll-options-list {
  display: grid;
  gap: 0.4rem;
}

.poll-option {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #1a212e;
  color: var(--text);
  padding: 0.35rem 0.45rem;
  display: grid;
  gap: 0.2rem;
}

.poll-option.is-voted {
  border-color: var(--accent);
}

.poll-option-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.poll-progress {
  width: 100%;
  height: 7px;
  background: #263248;
  border-radius: 999px;
  overflow: hidden;
}

.poll-progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

.poll-option button {
  text-align: left;
}

.poll-votes-total {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.composer {
  border-top: 1px solid var(--border);
  background: rgba(27, 31, 38, 0.97);
  padding: 0.8rem;
  display: grid;
  align-content: start;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  z-index: 8;
}

.composer textarea {
  min-height: 52px;
  max-height: 180px;
  resize: vertical;
}

.composer.dragover {
  border-top-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(76, 184, 106, 0.5);
}

.drop-hint {
  font-size: 0.84rem;
  color: var(--muted);
}

.pending-image {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  background: #151c28;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
}

.composer-actions button {
  min-height: 38px;
  padding: 0.42rem 0.8rem;
}

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.65rem;
}

.member-item {
  display: grid;
  grid-template-columns: 1fr max-content;
  align-items: center;
  gap: 0.5rem;
}

.member-identity {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.member-name {
  font-size: 1rem;
  white-space: nowrap;
}

.member-item .user-avatar-icon {
  width: 24px;
  height: 24px;
}

.voice-participant.is-speaking .voice-participant-name,
.member-item.is-speaking .member-name {
  color: #8df2a8;
}

.voice-participant.is-speaking .user-avatar-icon,
.member-item.is-speaking .user-avatar-icon {
  border-color: #74e793;
  box-shadow: 0 0 0 2px rgba(76, 184, 106, 0.33), 0 0 10px rgba(76, 184, 106, 0.72);
}

.voice-controls {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.45rem;
}

.mute-btn {
  text-align: left;
}

.mute-btn.active {
  background: #3a1e1e;
  border-color: #b75555;
  color: #ffbaba;
}

.mute-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.member-online {
  color: var(--accent);
  white-space: nowrap;
}

.member-offline {
  color: var(--muted);
  white-space: nowrap;
}

.settings {
  margin: 0.8rem;
  padding: 0.9rem;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.settings-grid > div {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  display: grid;
  gap: 0.45rem;
}

.settings-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

#errorDialog {
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: #2a1b1b;
  color: #ffe3e3;
  max-width: 420px;
}

#errorDialog::backdrop,
#changelogDialog::backdrop,
#pollDialog::backdrop,
#imagePreviewDialog::backdrop,
#voiceUserVolumeDialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

#changelogDialog {
  width: min(760px, 94vw);
  max-height: min(86vh, 900px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #121722;
  color: var(--text);
  padding: 0.8rem;
}

.changelog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.changelog-header h2 {
  margin: 0;
  font-size: 1.45rem;
}

.changelog-content {
  max-height: min(72vh, 760px);
  overflow-y: auto;
  padding-right: 0.35rem;
}

.changelog-release {
  margin-bottom: 1rem;
}

.changelog-release h3 {
  margin: 0 0 0.45rem;
  font-size: 1.2rem;
}

.changelog-release ul {
  margin: 0;
  padding-left: 1.2rem;
  list-style: disc;
}

.changelog-release li {
  margin-bottom: 0.25rem;
  font-size: 1.02rem;
  line-height: 1.45;
}

#pollDialog {
  width: min(540px, 94vw);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #121722;
  color: var(--text);
  padding: 0.8rem;
}

.poll-dialog-header h3 {
  margin: 0 0 0.6rem;
}

.poll-form {
  display: grid;
  gap: 0.55rem;
}

.poll-options {
  display: grid;
  gap: 0.4rem;
}

.poll-option-input {
  display: grid;
  grid-template-columns: 1fr max-content;
  gap: 0.4rem;
  align-items: center;
}

.poll-option-input button {
  padding: 0.35rem 0.5rem;
}

.poll-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#imagePreviewDialog {
  width: min(96vw, 1400px);
  max-width: none;
  max-height: min(96vh, 1200px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #121722;
  color: var(--text);
  padding: 0.55rem;
}

.image-preview-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 0.4rem;
}

.image-preview-body {
  max-height: calc(96vh - 70px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1320;
  padding: 0.35rem;
}

.image-preview-body img {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
}

#voiceUserVolumeDialog {
  width: min(420px, 92vw);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #121722;
  color: var(--text);
  padding: 0.8rem;
}

.voice-volume-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.voice-volume-header h3 {
  margin: 0;
}

.voice-volume-body {
  display: grid;
  gap: 0.55rem;
}

.voice-volume-control {
  display: grid;
  grid-template-columns: 1fr max-content;
  align-items: center;
  gap: 0.55rem;
}

#voiceUserVolumeRange {
  width: 100%;
}

#voiceUserMuteBtn.active {
  background: #3a1e1e;
  border-color: #b75555;
  color: #ffbaba;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 220px 1fr;
  }

  .members {
    display: none;
  }
}

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(140px, 34vh) minmax(0, 1fr);
    height: calc(100dvh - 58px);
    overflow: hidden;
  }

  .channels,
  .members {
    order: 1;
  }

  .channels {
    gap: 0.65rem;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
  }

  .channel-group-voice {
    order: 1;
  }

  .channel-group-text {
    order: 2;
  }

  .voice-controls {
    order: 3;
    margin-top: 0;
  }

  .chat {
    order: 2;
    min-height: 0;
    height: 100%;
  }

  .messages {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (hover: none), (pointer: coarse) {
  .message-menu {
    opacity: 1;
    pointer-events: auto;
  }
}
