:root {
  --bg-main: #090909;
  --bg-panel: #151515;
  --bg-soft: #101010;
  --bg-input: #181818;
  --accent: #df00ff;
  --accent-soft: rgba(223, 0, 255, 0.18);
  --border: #292929;
  --text: #d3d3d3;
  --text-muted: #777777;
  --general-grow: 0.78;
  --private-grow: 0.22;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg-main);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.accent-text {
  color: var(--accent);
}

.app,
.screen {
  width: 100%;
  height: 100dvh;
}

.screen--auth,
.screen--owner-choice {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  background: radial-gradient(circle at top, #1a0d1c 0, var(--bg-main) 42%);
}

.window {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 26px 24px 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(21, 21, 21, 0.97);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.55);
}

.auth-window h1,
.owner-window h2 {
  margin: 0 0 8px;
  text-align: center;
  font-size: clamp(34px, 7vw, 52px);
  line-height: 1;
}

.owner-window h2 {
  font-size: 34px;
}

.auth-subtitle,
.owner-subtitle {
  margin: 0 0 22px;
  color: #969696;
  text-align: center;
  font-size: 14px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d0d0d;
}

.auth-tab {
  height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #888;
  cursor: pointer;
  font-weight: 700;
}

.auth-tab.is-active {
  background: var(--accent-soft);
  color: #fff;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  color: #999;
  font-size: 12px;
  text-align: left;
}

.field-hint {
  margin: -7px 0 12px;
  color: #777;
  font-size: 12px;
  text-align: left;
}

#auth-screen input,
#auth-screen select {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0 0 14px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-input);
  color: #fff;
}

#auth-screen input::placeholder {
  color: #626262;
}

#auth-screen input:focus,
#auth-screen select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 0;
  color: #cecece;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.checkbox input {
  width: 18px !important;
  height: 18px !important;
  margin: 2px 0 0 !important;
  padding: 0 !important;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.text-button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.btn {
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  transition: filter 0.18s ease, transform 0.18s ease;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.6;
}

.btn-purple {
  background: var(--accent);
  box-shadow: 0 0 18px rgba(223, 0, 255, 0.22);
}

.btn-secondary {
  border: 1px solid #393939;
  background: #292929;
}

.btn-danger {
  border: 1px solid #7c2424;
  background: #591414;
}

.btn-ok {
  border: 1px solid #1c722d;
  background: #11501d;
}

.btn-sm {
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.full-width {
  width: 100%;
}

#auth-submit {
  height: 54px;
  margin-top: 18px;
  border-radius: 14px;
  font-size: 17px;
}

.rules-mini {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
  color: #a9a9a9;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}

.rules-mini p {
  margin: 7px 0;
}

.rules-mini .btn {
  margin-top: 10px;
}

.stack {
  display: grid;
  gap: 10px;
}

.layout {
  position: relative;
  display: flex;
  width: 100%;
  height: 100dvh;
  background: #000;
}

.chat-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #000;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 9px 14px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: #0d0d0d;
}

.chat-header__left {
  min-width: 0;
}

.chat-header__title {
  font-size: 17px;
  font-weight: 800;
}

.chat-header__room {
  margin-top: 3px;
  overflow: hidden;
  color: #7f7f7f;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-switcher {
  max-width: 220px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid #373737;
  border-radius: 8px;
  background: #171717;
  color: #fff;
}

.icon-button {
  height: 34px;
  padding: 0 11px;
  border: 1px solid #353535;
  border-radius: 8px;
  background: #202020;
  color: #bbb;
  cursor: pointer;
}

.layout-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 5px 10px;
  flex: 0 0 auto;
  border-bottom: 1px solid #202020;
  background: #0b0b0b;
}

.layout-toolbar__label {
  margin-right: 4px;
  color: #666;
  font-size: 11px;
}

.layout-choice {
  min-height: 25px;
  padding: 0 9px;
  border: 1px solid #303030;
  border-radius: 7px;
  background: #171717;
  color: #888;
  cursor: pointer;
  font-size: 11px;
}

.layout-choice.is-active {
  border-color: rgba(223, 0, 255, 0.55);
  background: var(--accent-soft);
  color: #fff;
}

.mobile-nav {
  display: none;
}

.conversation-stack {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  overflow: hidden;
}

.system-feed {
  display: flex;
  min-height: 72px;
  max-height: 112px;
  flex: 0 0 86px;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 1px solid #1e1e1e;
  background: #070707;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 27px;
  padding: 5px 13px;
  flex: 0 0 auto;
  border-bottom: 1px solid #202020;
  background: #0b0b0b;
  color: #666;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.section-title--private {
  color: #b46abe;
}

.private-target-label {
  max-width: 50%;
  overflow: hidden;
  color: #666;
  font-weight: 400;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

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

.chat-section--general {
  flex: var(--general-grow) 1 0;
}

.chat-section--private {
  flex: var(--private-grow) 1 0;
  background: #030303;
}

.chat-resizer {
  position: relative;
  height: 8px;
  flex: 0 0 8px;
  border-top: 1px solid #202020;
  border-bottom: 1px solid #202020;
  background: #111;
  cursor: row-resize;
  touch-action: none;
}

.chat-resizer::after {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 42px;
  height: 2px;
  border-radius: 4px;
  background: #444;
  content: "";
  transform: translateX(-50%);
}

.chat-resizer:hover::after,
body.is-resizing .chat-resizer::after {
  background: var(--accent);
}

body.is-resizing {
  cursor: row-resize;
  user-select: none;
}

.conversation-stack.private-collapsed .chat-section--private,
.conversation-stack.private-collapsed .chat-resizer {
  display: none;
}

.system-list,
.messages-list,
.users-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.system-list,
.messages-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #2b2b2b #0b0b0b;
  scrollbar-width: thin;
}

.system-list li {
  padding: 4px 13px;
  border-bottom: 1px solid #101010;
  color: #777;
  font-size: 11px;
  font-style: italic;
  overflow-wrap: anywhere;
}

.msg-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
  padding: 5px 13px;
  border-bottom: 1px solid #0e0e0e;
  font-size: 13px;
  line-height: 1.45;
}

.msg-item:hover {
  background: rgba(255, 255, 255, 0.018);
}

.msg-time {
  min-width: 38px;
  flex: 0 0 auto;
  color: #3d3d3d;
  font-size: 10px;
}

.msg-body {
  min-width: 0;
  overflow-wrap: anywhere;
}

.nick-link {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-weight: 700;
}

.nick-link:hover {
  text-decoration: underline;
}

.msg-target {
  color: #a962b3;
  font-size: 12px;
}

.msg-text {
  color: #d0d0d0;
  white-space: pre-wrap;
}

.smile-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
  flex: 0 0 40px;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid #202020;
  background: #0b0b0b;
}

.smile-btn {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0.82;
}

.smile-btn:hover {
  opacity: 1;
}

.smile,
.smile-btn img {
  display: inline-block;
  width: 22px;
  height: 22px;
  vertical-align: middle;
}

.tools-container {
  padding: 5px 8px;
  flex: 0 0 auto;
  border-top: 1px solid #202020;
  background: #101010;
}

.tools-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.tool-group {
  display: flex;
  gap: 2px;
}

.btn-tool {
  height: 27px;
  padding: 0 8px;
  border: 1px solid #363636;
  background: #222;
  color: #ddd;
  cursor: pointer;
  font-size: 10px;
  text-transform: uppercase;
}

.btn-tool:hover {
  background: #303030;
}

.btn-tool.square {
  width: 27px;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
}

#target-nickname {
  min-width: 120px;
  height: 27px;
  padding: 0 8px;
  flex: 1 1 auto;
  border: 1px solid #363636;
  background: #070707;
  color: var(--accent);
  font-size: 11px;
}

.mod-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  border-top: 1px dashed rgba(223, 0, 255, 0.5);
  background: #0c070d;
}

.mod-panel__top {
  min-width: 180px;
}

.mod-label {
  color: #999;
  font-size: 11px;
}

.mod-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.chat-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: #0b0b0b;
}

.input-row {
  display: flex;
  gap: 7px;
  padding: 9px;
}

#input {
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  flex: 1 1 auto;
  border: 1px solid #343434;
  border-radius: 7px;
  background: var(--bg-input);
  color: #fff;
}

#input:focus {
  border-color: var(--accent);
  outline: none;
}

.side-panel {
  display: flex;
  width: 210px;
  min-height: 0;
  padding: 8px;
  flex: 0 0 210px;
  flex-direction: column;
  overflow-y: auto;
  background: #101010;
  scrollbar-color: #2b2b2b #0b0b0b;
  scrollbar-width: thin;
}

.side-panel__header {
  flex: 0 0 auto;
}

.users-group {
  min-height: 0;
}

.g-title {
  margin: 12px 4px 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid #282828;
  color: #565656;
  font-size: 10px;
  text-transform: uppercase;
}

.u-item {
  padding: 5px 6px;
  border-radius: 5px;
  color: #aaa;
  cursor: pointer;
  font-size: 12px;
  overflow-wrap: anywhere;
  user-select: none;
}

.u-item:hover {
  background: #1b1b1b;
  color: #fff;
}

.u-item.is-self {
  color: var(--accent);
}

.u-item.is-friend::before {
  margin-right: 5px;
  color: #f0d35a;
  content: "★";
}

.unread-badge {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  margin-left: 3px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
}

.rules-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 1px solid #393939;
  border-radius: 16px;
  background: #121212;
  color: var(--text);
  box-shadow: 0 25px 100px rgba(0, 0, 0, 0.75);
}

.rules-dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(3px);
}

.rules-dialog__window {
  display: flex;
  max-height: calc(100dvh - 30px);
  flex-direction: column;
}

.rules-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}

.rules-dialog__header h2 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 24px;
}

.rules-dialog__header p {
  margin: 0;
  color: #777;
  font-size: 12px;
}

.dialog-close {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #393939;
  border-radius: 8px;
  background: #222;
  color: #bbb;
  cursor: pointer;
  font-size: 0;
}

.dialog-close::before,
.dialog-close::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
}

.dialog-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.dialog-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.rules-content {
  padding: 6px 20px 20px;
  overflow-y: auto;
}

.rules-content section {
  padding: 14px 0;
  border-bottom: 1px solid #242424;
}

.rules-content h3 {
  margin: 0 0 6px;
  color: #fff;
  font-size: 15px;
}

.rules-content p {
  margin: 0;
  color: #bdbdbd;
  font-size: 14px;
  line-height: 1.55;
}

.rules-dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 20px;
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: #0e0e0e;
}

@media (max-width: 960px) {
  .side-panel {
    width: 170px;
    flex-basis: 170px;
  }

  .tools-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .window {
    max-height: none;
  }

  .layout {
    display: block;
  }

  .chat-main {
    width: 100%;
    height: 100dvh;
    border-right: 0;
  }

  .chat-header {
    min-height: 54px;
    padding: 7px 9px;
  }

  .chat-header__title {
    font-size: 15px;
  }

  .room-switcher {
    max-width: 154px;
    font-size: 11px;
  }

  .icon-button {
    padding: 0 8px;
    font-size: 11px;
  }

  .layout-toolbar {
    display: none;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-height: 38px;
    flex: 0 0 38px;
    border-bottom: 1px solid #242424;
    background: #0d0d0d;
  }

  .mobile-nav__button {
    border: 0;
    border-right: 1px solid #242424;
    background: transparent;
    color: #777;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-nav__button.is-active {
    background: var(--accent-soft);
    color: #fff;
  }

  .conversation-stack {
    flex: 1 1 auto;
  }

  .system-feed {
    min-height: 64px;
    max-height: 96px;
    flex-basis: 76px;
  }

  .chat-resizer {
    display: none;
  }

  .mobile-view-general .chat-section--general {
    display: flex;
    flex: 1 1 auto;
  }

  .mobile-view-general .chat-section--private {
    display: none;
  }

  .mobile-view-private .system-feed,
  .mobile-view-private .chat-section--general {
    display: none;
  }

  .mobile-view-private .chat-section--private,
  .mobile-view-private .private-collapsed .chat-section--private {
    display: flex;
    flex: 1 1 auto;
  }

  .mobile-view-users .conversation-stack,
  .mobile-view-users .smile-bar,
  .mobile-view-users .tools-container,
  .mobile-view-users .mod-panel,
  .mobile-view-users .chat-footer {
    display: none !important;
  }

  .side-panel {
    position: absolute;
    inset: 92px 0 0;
    z-index: 20;
    display: none;
    width: 100%;
    padding: 12px 16px;
    background: #101010;
  }

  .mobile-view-users .side-panel {
    display: flex;
    position: relative;
    inset: auto;
    z-index: auto;
    min-height: 0;
    flex: 1 1 auto;
  }

  .layout.mobile-view-users {
    display: flex;
    flex-direction: column;
  }

  .mobile-view-users .chat-main {
    height: auto;
    flex: 0 0 auto;
  }

  .smile-bar {
    height: 38px;
    flex-basis: 38px;
  }

  .tools-container {
    padding: 5px;
  }

  .tools-row {
    display: grid;
    grid-template-columns: auto minmax(90px, 1fr) auto auto;
  }

  .btn-tool {
    padding: 0 6px;
  }

  .mod-panel {
    max-height: 108px;
    overflow-y: auto;
  }

  .input-row {
    gap: 5px;
    padding: 7px;
  }

  .input-row .btn {
    min-width: 58px;
    padding: 0 9px;
    font-size: 12px;
  }

  .msg-item {
    padding: 5px 9px;
  }

  .rules-dialog__footer {
    flex-direction: column;
  }

  .rules-dialog__footer .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .screen--auth,
  .screen--owner-choice {
    align-items: flex-start;
    padding: 12px 8px;
  }

  .window {
    width: 100%;
    padding: 21px 16px 18px;
    border-radius: 14px;
  }

  .auth-window h1 {
    font-size: 39px;
  }

  .chat-header__left {
    max-width: 112px;
  }

  .room-switcher {
    max-width: 138px;
  }

  .tools-row {
    grid-template-columns: auto minmax(80px, 1fr);
  }

  .tool-group {
    justify-content: stretch;
  }

  .tool-group .btn-tool:not(.square) {
    flex: 1;
  }

  #target-nickname {
    min-width: 80px;
  }

  .rules-dialog__header,
  .rules-content,
  .rules-dialog__footer {
    padding-right: 14px;
    padding-left: 14px;
  }
}

.msg-text a.youtube-link { color: #d69aea; text-decoration: underline; overflow-wrap: anywhere; }
