:root {
  color-scheme: dark;
  --bg: #111214;
  --rail: #0c0d0f;
  --side: #17181c;
  --chat: #1e1f24;
  --hover: #26272d;
  --line: #2c2d33;
  --text: #f3f4f6;
  --muted: #a1a3ab;
  --faint: #6f727c;
  --lime: #d6f25c;
  --lime-ink: #172000;
  --ok: #3dd68c;
  --danger: #f07178;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
a { color: var(--lime); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.btn {
  border: 1px solid var(--line);
  background: var(--hover);
  border-radius: 10px;
  padding: 10px 14px;
}
.btn-lime {
  background: var(--lime);
  color: var(--lime-ink);
  border-color: transparent;
  font-weight: 650;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
}
.btn.danger, button.danger { color: var(--danger); }

#boot {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

#shell {
  height: 100%;
  display: grid;
  grid-template-columns: 76px 256px minmax(0, 1fr) 236px;
  min-height: 0;
}

#rail {
  background: var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  overflow: auto;
}
.srv {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  border: 0;
  background: #2a2c33;
  color: white;
  font-weight: 700;
  position: relative;
}
.srv.is-on, .srv:hover { border-radius: 14px; }
.srv.is-on::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 4px;
  background: var(--lime);
}
.srv-add { background: var(--bg); color: var(--lime); font-size: 26px; }

#channels, #members {
  background: var(--side);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
#channels { position: relative; border-right: 1px solid #000; }
.side-head { padding: 12px; border-bottom: 1px solid var(--line); }
#serverBtn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 8px;
}
#serverBtn:hover { background: var(--hover); }
.pop {
  position: absolute;
  z-index: 5;
  top: 52px;
  left: 12px;
  right: 12px;
  background: #111216;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.pop button {
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 10px;
}
.pop button:hover { background: var(--hover); }
#chanList, #members { overflow: auto; padding: 8px; flex: 1; }
.group {
  color: var(--faint);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 14px 8px 6px;
}
.chan-row { display: flex; align-items: center; gap: 2px; }
.chan {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 7px 8px;
  color: var(--muted);
}
.chan:hover, .chan.is-on { background: var(--hover); color: var(--text); }
.chan.is-live { color: var(--ok); }
.chan-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prefix { width: 16px; color: var(--faint); }
.badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  font-size: 11px;
  padding: 1px 5px;
}
.chan-del {
  border: 0;
  background: transparent;
  color: var(--faint);
  width: 28px;
  opacity: 0;
}
.chan-row:hover .chan-del { opacity: 1; }
.voice-users { display: flex; flex-direction: column; gap: 2px; margin: 0 0 6px 22px; }
.voice-user, .member {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 4px;
  border-radius: 8px;
}
.voice-user img, .member img, #meAvatar, .msg img, .tile-face {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a2c33;
}
.member img { width: 32px; height: 32px; }
.voice-user.is-speaking img, .member.is-speaking img, #meAvatar.is-speaking, .tile.is-speaking .tile-face {
  box-shadow: 0 0 0 2px var(--ok);
}
.voice-user em { margin-left: auto; font-style: normal; color: var(--lime); font-size: 11px; }
.member { width: 100%; }
.member strong, .me-names strong { display: block; font-size: 14px; }
.member span, .me-names span, #voiceWhere, #topic { color: var(--faint); font-size: 12px; }
.member.is-on strong { color: var(--text); }
.member:not(.is-on) { opacity: .55; }

#voiceCard, #meBar {
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
}
#voiceCard strong { display: block; color: var(--ok); font-size: 13px; }
#hangBtn, .me-actions button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
}
.me-actions { margin-left: auto; display: flex; }
.me-actions button:hover, #hangBtn:hover { background: var(--hover); color: var(--text); }
.me-actions svg, #muteBtn svg, #deafenBtn svg, #shareBtn svg, #logoutBtn svg { width: 18px; height: 18px; }
.me-actions .is-off { color: var(--danger); }
.me-actions .is-on { color: var(--lime); }
.me-names { min-width: 0; }
.me-names strong, .me-names span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}
#meAvatar { width: 36px; height: 36px; }

#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat); }
#topbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
#topbar h2 { margin: 0; font-size: 16px; }
#topbar p { margin: 0; }
#openChannels { display: none; border: 0; background: var(--hover); border-radius: 8px; padding: 6px 8px; }

#stage {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  padding: 12px;
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: #14151a;
}
#stage.is-strip {
  flex: none;
  max-height: 200px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 240px));
}
.tile {
  position: relative;
  min-height: 160px;
  border-radius: 14px;
  overflow: hidden;
  background: #101116;
  display: grid;
  place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: none; }
.tile.is-live video { display: block; }
.tile.is-live .tile-face { display: none; }
.tile audio { display: none; }
.tile-face { width: 72px; height: 72px; }
.tile-name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, .55);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
}

#log { flex: 1; overflow: auto; padding: 16px 0; min-height: 0; }
.day, .older {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--faint);
  font-size: 12px;
  margin: 8px 16px;
}
.older { border: 0; background: transparent; width: calc(100% - 32px); }
.msg { display: grid; grid-template-columns: 48px 1fr; gap: 4px 12px; padding: 2px 16px; }
.msg:hover { background: rgba(255, 255, 255, .03); }
.msg img { width: 40px; height: 40px; margin-top: 2px; }
.msg.is-group { grid-template-columns: 48px 1fr; }
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.msg-head { display: flex; gap: 8px; align-items: baseline; }
.msg-head time, .msg-hover-time { color: var(--faint); font-size: 12px; }
.msg-hover-time { opacity: 0; }
.msg:hover .msg-hover-time { opacity: 1; }

#composer { padding: 0 16px 16px; }
#box {
  width: 100%;
  resize: none;
  border: 0;
  border-radius: 12px;
  background: #2a2b32;
  padding: 12px 14px;
  min-height: 46px;
  max-height: 160px;
}
#box:focus { outline: 2px solid color-mix(in srgb, var(--lime) 55%, transparent); }

#home { flex: 1; display: grid; place-items: center; padding: 24px; }
.home-card { max-width: 460px; display: grid; gap: 12px; }
.home-card h2 { margin: 0; font-size: 28px; }
.home-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.invite-row { display: flex; gap: 8px; }
.invite-row input {
  flex: 1;
  border: 1px solid var(--line);
  background: #15161a;
  border-radius: 10px;
  padding: 10px 12px;
}

#toast, #hearBtn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: #0e0f12;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}
#toast { bottom: 20px; }
#hearBtn { bottom: 64px; }

#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 16px;
}
#modalForm {
  width: min(440px, 100%);
  background: #1a1b20;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
#modalForm h2 { margin: 0; font-size: 20px; }
#modalForm p { margin: 0; color: var(--muted); }
#modalInput {
  border: 1px solid var(--line);
  background: #111216;
  border-radius: 10px;
  padding: 10px 12px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { border-radius: 10px; border: 0; padding: 10px 12px; background: var(--hover); }
#modalOk { background: var(--lime); color: var(--lime-ink); font-weight: 700; }
#modalOk.danger { background: var(--danger); color: white; }

.gate-body { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate { width: min(560px, 100%); display: grid; gap: 14px; }
.brand-lockup { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: .04em; }
.mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--lime);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--lime) 18%, transparent);
}
.gate h1 { margin: 0; font-size: clamp(32px, 5vw, 48px); line-height: 1.05; }
.lead, .gate-points { color: var(--muted); line-height: 1.5; }
.gate-points { margin: 0; padding-left: 18px; }
.gate-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.gate-error { color: var(--danger); margin: 0; }
.gate-hint { color: var(--faint); font-size: 13px; }
.gate-hint code { color: var(--text); }

@media (max-width: 1100px) {
  #shell { grid-template-columns: 72px 240px minmax(0, 1fr); }
  #members { display: none; }
}
@media (max-width: 800px) {
  #shell { grid-template-columns: 64px minmax(0, 1fr); }
  #channels {
    display: none;
    position: absolute;
    z-index: 8;
    inset: 0 auto 0 64px;
    width: min(280px, calc(100vw - 64px));
  }
  #shell.show-channels #channels { display: flex; }
  #openChannels { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
