*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #1e1f22;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #313338;
  --bg-hover: #35373c;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --red: #ed4245;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --border: #3f4147;
  --radius: 8px;
}

html,
body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
}

.hidden {
  display: none !important;
}

/* ── Login ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1f22 0%, #2b2d31 50%, #1a1b1e 100%);
}

.login-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}

/* ── App layout ── */
#app {
  display: grid;
  grid-template-columns: 72px 240px 1fr 220px;
  grid-template-rows: 1fr auto;
  height: 100vh;
  overflow: hidden;
}

/* Server rail */
.rail {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  border-right: 1px solid var(--border);
}

.rail-icon {
  width: 48px;
  height: 48px;
  background: var(--accent);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: border-radius 0.2s;
}

.rail-icon:hover {
  border-radius: 12px;
}

/* Channels sidebar */
.sidebar {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.sidebar-header {
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.channel-list {
  padding: 12px 8px;
  flex: 1;
}

.channel-category {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}

.channel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  transition: background 0.1s, color 0.1s;
}

.channel.active,
.channel:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.channel .hash {
  font-size: 18px;
  opacity: 0.7;
}

.user-panel {
  background: var(--bg-tertiary);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-info .name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info .status {
  font-size: 11px;
  color: var(--text-muted);
}

.panel-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.panel-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Main chat */
.main {
  display: flex;
  flex-direction: column;
  background: var(--bg-tertiary);
  min-width: 0;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.chat-header .hash {
  color: var(--text-muted);
  font-size: 20px;
}

/* Screen share */
.screen-area {
  margin: 12px 16px 0;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-secondary);
  font-size: 13px;
  font-weight: 600;
}

.screen-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}

.screen-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

#screen-video {
  width: 100%;
  max-height: 360px;
  display: block;
  background: #000;
  object-fit: contain;
}

.voice-btn.active-share {
  background: var(--green);
  color: #fff;
}

.member.sharing .member-name::after {
  content: ' 📺';
  font-size: 12px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 14px;
  padding: 4px 0;
  border-radius: 4px;
}

.message:hover {
  background: rgba(0, 0, 0, 0.06);
}

.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.msg-body .msg-author {
  font-weight: 600;
  font-size: 15px;
  margin-right: 8px;
}

.msg-body .msg-time {
  font-size: 11px;
  color: var(--text-muted);
}

.msg-body .msg-text {
  font-size: 15px;
  line-height: 1.4;
  margin-top: 2px;
  word-break: break-word;
}

.system-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

.chat-input-wrap {
  padding: 0 16px 20px;
}

.chat-input {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 2px;
  border: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.chat-input button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  margin: 4px;
  transition: background 0.15s;
}

.chat-input button:hover {
  background: var(--accent-hover);
}

/* Members list */
.members {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}

.members h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 14px;
}

.member-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.member-ping {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.member-ping.good { color: var(--green); }
.member-ping.ok { color: #f0b232; }
.member-ping.bad { color: var(--red); }

.speaking-icon {
  font-size: 14px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s, transform 0.15s;
}

.member.speaking .speaking-icon {
  opacity: 1;
  transform: scale(1);
}

.member.speaking .member-avatar {
  box-shadow: 0 0 0 2px var(--green);
  animation: speak-glow 0.8s ease-in-out infinite alternate;
}

@keyframes speak-glow {
  from { box-shadow: 0 0 0 2px var(--green); }
  to { box-shadow: 0 0 0 2px var(--green), 0 0 8px rgba(35, 165, 89, 0.5); }
}

.member:hover {
  background: var(--bg-hover);
}

.member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.member-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

/* Voice bar */
.voice-bar {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.voice-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.voice-info .pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.voice-info span {
  font-size: 14px;
  color: var(--text-muted);
}

.voice-controls {
  display: flex;
  gap: 8px;
}

.voice-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.voice-btn:hover {
  background: var(--bg-hover);
}

.voice-btn.active-off {
  background: var(--red);
  color: #fff;
}

.voice-btn.leave {
  background: var(--red);
  color: #fff;
  border-radius: 8px;
  width: auto;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
}

.user-panel.speaking .user-avatar {
  box-shadow: 0 0 0 2px var(--green);
  animation: speak-glow 0.8s ease-in-out infinite alternate;
}

/* Settings modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  position: relative;
  background: var(--bg-secondary);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--border);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  z-index: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

.modal-body select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

.modal-body select:focus {
  border-color: var(--accent);
}

.modal-footer {
  padding: 0 24px 20px;
}

.settings-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto;
  }

  .rail,
  .sidebar,
  .members {
    display: none;
  }
}
