:root {
  color-scheme: dark;
  --bg0: #070b10;
  --bg1: #0c1218;
  --bg2: #111a22;
  --bg3: #16202a;
  --line: rgba(120, 200, 255, 0.14);
  --line2: #243241;
  --text: #e8eef4;
  --muted: #8a9eae;
  --soft: #b7c9d6;
  --accent: #7ec8ff;
  --accent2: #5eead4;
  --warn: #fbbf24;
  --err: #f87171;
  --join: #6ee7b7;
  --part: #94a3b8;
  --nick-a: #7dd3fc;
  --nick-b: #c4b5fd;
  --nick-c: #f9a8d4;
  --nick-d: #86efac;
  --nick-e: #fcd34d;
  --nick-f: #fda4af;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1000px 520px at 12% -8%, #1a3a4a 0%, transparent 55%),
    radial-gradient(800px 400px at 95% 10%, #1a2a40 0%, transparent 50%),
    var(--bg0);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 12, 16, 0.72);
  backdrop-filter: blur(10px);
}
.top-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  font-weight: 650;
}
.brand .sub { color: var(--muted); font-size: 0.85rem; }
.connect-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.chip {
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  color: var(--soft);
  white-space: nowrap;
}
.chip strong { color: var(--accent); font-weight: 600; }
.badge-ro {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.35);
  color: var(--soft);
}
.badge-live {
  background: rgba(94, 234, 212, 0.12);
  border-color: rgba(94, 234, 212, 0.4);
  color: var(--accent2);
}
.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}
.hidden { display: none !important; }
button.btn-primary {
  background: linear-gradient(180deg, rgba(126, 200, 255, 0.22), rgba(126, 200, 255, 0.1));
  border-color: rgba(126, 200, 255, 0.45);
  color: var(--accent);
  font-weight: 600;
}
button.btn-primary:hover {
  border-color: rgba(126, 200, 255, 0.7);
  color: #cfefff;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--part);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.12);
}
.status.online .dot {
  background: var(--join);
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.15);
}
.status.connecting .dot,
.status.registering .dot,
.status.starting .dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.15);
  animation: pulse 1.1s ease-in-out infinite;
}
.status.error .dot,
.status.offline .dot,
.status.stale .dot {
  background: var(--err);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
}
@keyframes pulse {
  50% { opacity: 0.45; }
}

.shell {
  flex: 1 1 auto;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0.65rem;
}

.client {
  min-height: 0;
  height: min(78vh, 860px);
  display: grid;
  grid-template-columns: 220px 1fr 200px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 18, 24, 0.88);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
}
.pane + .pane { border-left: 1px solid var(--line); }
.pane-head {
  flex: 0 0 auto;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.18);
}
.pane-head .count {
  font-family: var(--mono);
  letter-spacing: 0;
  text-transform: none;
  color: var(--soft);
}
.pane-body {
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
}

.rooms { list-style: none; margin: 0; padding: 0.4rem; }
.rooms li button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--soft);
  font: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.rooms li button:hover { background: rgba(126, 200, 255, 0.08); }
.rooms li button.active {
  background: rgba(126, 200, 255, 0.14);
  color: var(--text);
}
.rooms .name {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
}
.rooms .meta {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  padding: 0.65rem 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.msg {
  display: grid;
  grid-template-columns: 4.4rem minmax(0, 1fr);
  gap: 0.55rem;
  padding: 0.28rem 0.35rem;
  border-radius: 8px;
  line-height: 1.45;
  font-size: 0.92rem;
}
.msg:hover { background: rgba(255, 255, 255, 0.025); }
.msg .time {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  padding-top: 0.18rem;
  user-select: none;
}
.msg .body { min-width: 0; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .nick {
  font-weight: 650;
  margin-right: 0.4rem;
  font-family: var(--mono);
  font-size: 0.86rem;
}
.msg.system .body { color: var(--muted); font-size: 0.86rem; }
.msg.system .body .event { color: var(--part); }
.msg.join .body { color: var(--join); }
.msg.part .body { color: var(--part); }
.msg.topic .body { color: var(--accent); }
.msg.error .body { color: var(--err); }
.msg.mine { background: rgba(126, 200, 255, 0.05); }
.msg.notice .nick { opacity: 0.85; }
.empty {
  color: var(--muted);
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.5;
}

.members { list-style: none; margin: 0; padding: 0.4rem; }
.members li {
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--soft);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.members li:hover { background: rgba(255, 255, 255, 0.03); }
.members .prefix {
  color: var(--warn);
  width: 0.85rem;
  text-align: center;
  flex: 0 0 auto;
}
.members .self { opacity: 0.65; font-style: italic; }
.members .me {
  background: rgba(126, 200, 255, 0.1);
  outline: 1px solid rgba(126, 200, 255, 0.18);
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
}
.composer-nick {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  max-width: 7.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 0.25rem;
}
.composer input[type="text"] {
  width: 100%;
  border: 1px solid var(--line2);
  background: var(--bg1);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}
.composer input[type="text"]:focus {
  border-color: rgba(126, 200, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(126, 200, 255, 0.1);
}
.composer input[type="text"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Auth dialog */
.auth-dialog {
  border: 1px solid rgba(120, 200, 255, 0.22);
  border-radius: 16px;
  background: rgba(6, 10, 14, 0.98);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100vw - 1.5rem));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
}
.auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
}
.auth-form { padding: 1rem 1.1rem 1.1rem; }
.auth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.auth-head h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.auth-tab {
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--muted);
  border-radius: 10px;
  padding: 0.45rem 0.4rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.auth-tab.active {
  color: var(--text);
  border-color: rgba(126, 200, 255, 0.45);
  background: rgba(126, 200, 255, 0.12);
  font-weight: 600;
}
.auth-blurb {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.7rem;
  font-size: 0.82rem;
  color: var(--muted);
}
/* class display:flex beats UA [hidden]; keep toggled fields actually hidden */
.field[hidden] {
  display: none;
}
.field input[type="text"],
.field input[type="password"],
.field input[type="email"] {
  border: 1px solid var(--line2);
  background: var(--bg1);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}
.field input:focus {
  border-color: rgba(126, 200, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(126, 200, 255, 0.1);
}
.field.check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--soft);
  font-size: 0.84rem;
}
.auth-error {
  margin: 0 0 0.65rem;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.84rem;
}
.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.msg-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.msg-head .channel {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: 0;
  text-transform: none;
  font-weight: 650;
}
.msg-head .topic {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.footer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 18, 24, 0.75);
  font-size: 0.86rem;
  color: var(--soft);
}
.footer-bar .hint {
  color: var(--muted);
  font-size: 0.82rem;
}
.footer-bar code {
  font-family: var(--mono);
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
}
.actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
button.btn {
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
button.btn:hover { border-color: rgba(126, 200, 255, 0.35); color: var(--accent); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.details {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 0.75rem 1.25rem;
}
details.info {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(3, 6, 10, 0.94);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 12px 36px rgba(0, 0, 0, 0.45);
  padding: 0.35rem 0.9rem 0.2rem;
}
details.info[open] {
  background: rgba(2, 5, 9, 0.97);
  border-color: rgba(120, 200, 255, 0.2);
}
details.info summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.55rem 0;
  list-style: none;
  user-select: none;
}
details.info summary::-webkit-details-marker { display: none; }
details.info summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.45rem;
  color: var(--accent);
  transition: transform 0.15s ease;
}
details.info[open] summary::before { transform: rotate(90deg); }
details.info[open] summary {
  border-bottom: 1px solid var(--line);
  margin-bottom: 0;
  color: var(--soft);
}
.info-panel {
  position: relative;
  padding: 0.85rem 2rem 0.15rem 0;
}
.info-close {
  position: absolute;
  top: 0.35rem;
  right: 0;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--soft);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.info-close:hover {
  border-color: rgba(126, 200, 255, 0.4);
  color: var(--accent);
  background: rgba(126, 200, 255, 0.08);
}
.info-grid {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.45rem 0.75rem;
  padding-bottom: 0.9rem;
  font-size: 0.9rem;
}
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; font-family: var(--mono); font-size: 0.86rem; }
.info-note { color: var(--muted); font-size: 0.84rem; padding-bottom: 0.9rem; line-height: 1.5; }

@media (max-width: 900px) {
  .client {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: min(82vh, 920px);
  }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--line); }
  .rooms-pane { max-height: 140px; }
  .members-pane { max-height: 150px; }
  .msg { grid-template-columns: 3.6rem 1fr; }
  .composer {
    grid-template-columns: 1fr auto;
  }
  .composer-nick {
    grid-column: 1 / -1;
    max-width: none;
  }
}
