:root {
  color-scheme: light dark;
  --page: #edf2f5;
  --panel: #ffffff;
  --panel-soft: #f5f7f9;
  --ink: #14202b;
  --muted: #66727d;
  --line: #d8e0e6;
  --brand: #0f6f71;
  --brand-strong: #0b5658;
  --accent: #d58a16;
  --error: #b42318;
  --success: #16835b;
  --message-own: #e6f4f1;
  --message-bot: #f5f1e6;
  --shadow: 0 14px 34px rgba(24, 39, 53, .08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand), transparent 45%);
  outline-offset: 2px;
}

.topbar {
  min-height: 64px;
  padding: 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand,
.stats-link {
  color: inherit;
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--panel);
  font-size: 20px;
}

.stats-link {
  color: var(--brand);
  font-weight: 700;
}

.chat-shell {
  width: min(1180px, 100%);
  min-height: calc(100dvh - 114px);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px);
}

.channel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 50px);
  line-height: 1;
}

h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.topic {
  max-width: 720px;
  margin: 9px 0 0;
  color: var(--muted);
}

.connection-state {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

.state-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #98a2ad;
}

.connection-state[data-state="connecting"] .state-dot,
.connection-state[data-state="joining"] .state-dot {
  background: var(--accent);
}

.connection-state[data-state="joined"] .state-dot {
  background: var(--success);
}

.connection-state[data-state="closed"] .state-dot {
  background: var(--error);
}

.join-panel {
  min-height: 280px;
  padding: clamp(24px, 5vw, 52px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(300px, 1.25fr);
  align-items: center;
  gap: clamp(28px, 7vw, 92px);
}

.join-panel p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
}

.join-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
}

.join-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input {
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
}

button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 5px;
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  background: var(--brand-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.form-error {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--error);
  font-size: 14px;
}

.chat-panel {
  height: min(720px, calc(100dvh - 205px));
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  grid-template-rows: minmax(0, 1fr) 66px;
  overflow: hidden;
}

.messages {
  padding: 18px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message {
  display: grid;
  grid-template-columns: 54px minmax(72px, 130px) minmax(0, 1fr);
  gap: 10px;
  padding: 5px 8px;
  border-radius: 4px;
  line-height: 1.45;
}

.message[data-own="true"] {
  background: var(--message-own);
}

.message[data-bot="true"] {
  background: var(--message-bot);
}

.message-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.message-nick {
  overflow: hidden;
  color: var(--brand);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-text {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.system {
  display: block;
  padding-left: 72px;
  color: var(--muted);
  font-size: 14px;
}

.message.error {
  color: var(--error);
}

.people-panel {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--panel-soft);
  overflow-y: auto;
}

.people-head {
  position: sticky;
  top: 0;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.people-head h2 {
  margin: 0;
  font-size: 14px;
}

.people-head span {
  color: var(--muted);
  font-size: 13px;
}

.people-panel ul {
  margin: 0;
  padding: 8px 10px 18px;
  list-style: none;
}

.people-panel li {
  padding: 5px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-form {
  padding: 9px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
}

.message-form input {
  height: 46px;
}

footer {
  min-height: 50px;
  padding: 8px max(18px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
}

footer button {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  color: var(--error);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.irc-bold {
  font-weight: 800;
}

.irc-italic {
  font-style: italic;
}

.irc-underline {
  text-decoration: underline;
}

.irc-fg-0 { color: #ffffff; }
.irc-fg-1 { color: #111111; }
.irc-fg-2 { color: #2453a6; }
.irc-fg-3 { color: #15803d; }
.irc-fg-4 { color: #c62828; }
.irc-fg-5 { color: #8b3a3a; }
.irc-fg-6 { color: #7e22ce; }
.irc-fg-7 { color: #b45309; }
.irc-fg-8 { color: #8a7300; }
.irc-fg-9 { color: #2f9e44; }
.irc-fg-10 { color: #0f8b8d; }
.irc-fg-11 { color: #0e7490; }
.irc-fg-12 { color: #2563eb; }
.irc-fg-13 { color: #c026d3; }
.irc-fg-14 { color: #667085; }
.irc-fg-15 { color: #8c98a5; }

.irc-bg-0 { background-color: #ffffff; }
.irc-bg-1 { background-color: #111111; }
.irc-bg-2 { background-color: #2453a6; }
.irc-bg-3 { background-color: #15803d; }
.irc-bg-4 { background-color: #c62828; }
.irc-bg-5 { background-color: #8b3a3a; }
.irc-bg-6 { background-color: #7e22ce; }
.irc-bg-7 { background-color: #b45309; }
.irc-bg-8 { background-color: #8a7300; }
.irc-bg-9 { background-color: #2f9e44; }
.irc-bg-10 { background-color: #0f8b8d; }
.irc-bg-11 { background-color: #0e7490; }
.irc-bg-12 { background-color: #2563eb; }
.irc-bg-13 { background-color: #c026d3; }
.irc-bg-14 { background-color: #667085; }
.irc-bg-15 { background-color: #8c98a5; }

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d141a;
    --panel: #151e26;
    --panel-soft: #10181f;
    --ink: #edf3f7;
    --muted: #9ba8b2;
    --line: #2e3b45;
    --brand: #64c3c1;
    --brand-strong: #3da6a4;
    --accent: #e5a941;
    --error: #ff8a80;
    --success: #56d69a;
    --message-own: #17322f;
    --message-bot: #302b1e;
    --shadow: 0 14px 34px rgba(0, 0, 0, .35);
  }

  .brand-mark {
    background: var(--ink);
    color: var(--page);
  }
}

@media (max-width: 760px) {
  .chat-shell {
    min-height: calc(100dvh - 114px);
    padding: 14px 0 0;
  }

  .channel-head {
    padding: 0 14px;
    align-items: start;
  }

  .topic {
    display: none;
  }

  .connection-state {
    max-width: 48%;
    align-items: start;
  }

  .join-panel,
  .chat-panel {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .join-panel {
    min-height: 330px;
    grid-template-columns: 1fr;
    align-content: center;
    gap: 28px;
  }

  .chat-panel {
    height: calc(100dvh - 179px);
    min-height: 420px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 66px;
  }

  .people-panel {
    display: none;
  }

  .message {
    grid-template-columns: 46px minmax(64px, 90px) minmax(0, 1fr);
    gap: 7px;
    padding-right: 3px;
    padding-left: 3px;
    font-size: 14px;
  }

  .message.system {
    padding-left: 53px;
  }

  .messages {
    padding: 12px 9px;
  }
}

@media (max-width: 460px) {
  .topbar {
    min-height: 56px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .channel-head {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 34px;
  }

  .join-controls {
    grid-template-columns: 1fr;
  }

  .join-controls button {
    height: 48px;
  }

  .message {
    grid-template-columns: 42px 76px minmax(0, 1fr);
  }

  .message-time {
    font-size: 12px;
  }
}
