:root {
  --bg-deep: #0c0e14;
  --bg-card: rgba(22, 26, 38, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eaef;
  --text-muted: #8b92a8;
  --accent: #6c9eff;
  --accent-soft: rgba(108, 158, 255, 0.15);
  --glow: rgba(108, 158, 255, 0.35);
  --radius: 14px;
  --font: "Noto Sans SC", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
  line-height: 1.5;
}

.page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 1.25rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  align-items: start;
}

.page-layout--no-chat {
  grid-template-columns: 1fr;
}

.chat-panel--hidden {
  display: none !important;
}

.page-layout__main {
  min-width: 0;
}

.chat-panel {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 1rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  height: calc(100vh - 2rem);
  max-height: calc(100vh - 2rem);
  height: calc(100dvh - 2rem);
  max-height: calc(100dvh - 2rem);
  min-height: 0;
  box-sizing: border-box;
}

.chat-panel__dismiss {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  z-index: 2;
  padding: 0.25rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  background: rgba(7, 9, 14, 0.5);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  line-height: 1.2;
}

.chat-panel__dismiss:hover {
  color: var(--text);
  border-color: rgba(108, 158, 255, 0.35);
}

.chat-panel__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.45rem 0.5rem;
  padding-right: 3.25rem;
}

.chat-panel__nick {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
}

.chat-panel__nick-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-panel__nick-input {
  flex: 1;
  min-width: 0;
  max-width: 10rem;
  padding: 0.38rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(7, 9, 12, 0.55);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  outline: none;
}

.chat-panel__nick-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-panel__nick-rand {
  flex-shrink: 0;
  padding: 0.38rem 0.5rem;
  border: 1px solid rgba(108, 158, 255, 0.4);
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent);
  background: var(--accent-soft);
}

.chat-panel__nick-rand:hover {
  filter: brightness(1.08);
}

.chat-panel__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.chat-panel__badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(108, 158, 255, 0.35);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
}

.chat-panel__status {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chat-panel__status--ok {
  color: #86efac;
}

.chat-panel__myid {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.chat-panel__myid-label {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--accent);
}

.chat-panel__myid-code {
  flex: 1;
  min-width: 0;
  display: block;
  padding: 0.35rem 0.45rem;
  font-size: 0.68rem;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  word-break: break-all;
  color: var(--text);
  background: rgba(7, 9, 14, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chat-panel__private {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chat-panel__private-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}

.chat-panel__private-check input {
  width: 0.95rem;
  height: 0.95rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.chat-panel__private-target {
  flex: 1;
  min-width: 7rem;
  padding: 0.38rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(7, 9, 12, 0.55);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  outline: none;
}

.chat-panel__private-target:focus:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-panel__private-target:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-panel__log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  line-height: 1.45;
  background: rgba(7, 9, 14, 0.55);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-soft, var(--text-muted));
}

.chat-line {
  display: flex;
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.chat-line:last-child {
  margin-bottom: 0;
}

.chat-line--me {
  justify-content: flex-end;
}

.chat-line--srv {
  justify-content: flex-start;
}

.chat-line--err {
  justify-content: center;
}

.chat-line--join {
  justify-content: center;
}

.chat-line__row {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  max-width: 88%;
  min-width: 0;
}

.chat-line__row--me {
  flex-direction: row;
}

.chat-line__row--srv {
  flex-direction: row;
}

.chat-line__row--err {
  max-width: 100%;
  justify-content: center;
}

.chat-line__row--join {
  max-width: 100%;
  justify-content: center;
}

.chat-copy-id {
  flex-shrink: 0;
  padding: 0.3rem 0.45rem;
  font-size: 0.62rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(108, 158, 255, 0.35);
  border-radius: 8px;
  line-height: 1.2;
  font-family: inherit;
}

.chat-copy-id:hover {
  filter: brightness(1.08);
}

.chat-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 10000;
  max-width: min(90vw, 20rem);
  padding: 0.55rem 1.15rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: #f1f5f9;
  text-align: center;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(108, 158, 255, 0.4);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  transform: translateX(-50%) translateY(120%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s ease, opacity 0.28s ease;
}

.chat-toast.chat-toast--show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.chat-line__stack {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.chat-line--me .chat-line__stack {
  align-items: flex-end;
}

.chat-line--srv .chat-line__stack {
  align-items: flex-start;
}

.chat-line--err .chat-line__stack {
  align-items: center;
  max-width: 100%;
}

.chat-line--join .chat-line__stack {
  align-items: center;
  max-width: 100%;
}

.chat-bubble {
  width: fit-content;
  max-width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 12px;
  line-height: 1.45;
}

.chat-line--me .chat-bubble {
  color: #e8f1ff;
  background: linear-gradient(145deg, rgba(76, 129, 255, 0.45) 0%, rgba(56, 100, 220, 0.4) 100%);
  border: 1px solid rgba(108, 158, 255, 0.45);
  border-bottom-right-radius: 4px;
}

.chat-line--srv .chat-bubble {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-line--err .chat-bubble {
  max-width: 100%;
  color: #fb7185;
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.35);
  text-align: center;
}

.chat-line--join .chat-bubble {
  max-width: 100%;
  color: #7dd3c0;
  background: rgba(45, 212, 191, 0.1);
  border: 1px solid rgba(45, 212, 191, 0.35);
  text-align: center;
  font-size: 0.62rem;
  line-height: 1.35;
  padding: 0.28rem 0.5rem;
}

.chat-line--priv .chat-bubble {
  border-style: dashed;
}

.chat-line--me.chat-line--priv .chat-bubble {
  background: linear-gradient(145deg, rgba(167, 139, 250, 0.35) 0%, rgba(129, 90, 213, 0.32) 100%);
  border-color: rgba(167, 139, 250, 0.55);
}

.chat-line--srv.chat-line--priv .chat-bubble {
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.35);
}

.chat-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.22rem;
  padding: 0 0.2rem;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}

.chat-line--me .chat-time {
  text-align: right;
}

.chat-line--srv .chat-time {
  text-align: left;
}

.chat-line--err .chat-time {
  text-align: center;
}

.chat-line--join .chat-time {
  text-align: center;
  font-size: 0.55rem;
  margin-top: 0.12rem;
  opacity: 0.75;
}

.chat-panel__composer {
  position: relative;
  flex-shrink: 0;
}

.chat-panel__form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chat-panel__sticker-btn {
  flex-shrink: 0;
  padding: 0.5rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent);
  background: rgba(108, 158, 255, 0.12);
  border: 1px solid rgba(108, 158, 255, 0.35);
  border-radius: 10px;
  line-height: 1.2;
  font-family: inherit;
}

.chat-panel__sticker-btn:hover {
  background: rgba(108, 158, 255, 0.2);
}

.chat-sticker-pop {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.35rem);
  z-index: 50;
  padding: 0.55rem;
  max-height: 18rem;
  overflow-y: auto;
  background: rgba(15, 18, 28, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
}

.chat-sticker-pop__head {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
  padding: 0 0.15rem 0.35rem;
  border-bottom: 1px solid var(--border);
}

.chat-sticker-pack {
  margin-bottom: 0.65rem;
}

.chat-sticker-pack:last-child {
  margin-bottom: 0;
}

.chat-sticker-pop[hidden] {
  display: none !important;
}

.chat-sticker-pop__title {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  padding: 0 0.15rem;
}

.chat-sticker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.chat-sticker-grid button {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  padding: 0.2rem;
  margin: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chat-sticker-grid button:hover {
  background: rgba(108, 158, 255, 0.15);
  border-color: rgba(108, 158, 255, 0.4);
}

.chat-sticker-grid img {
  width: 100%;
  height: 100%;
  max-width: 40px;
  max-height: 40px;
  object-fit: contain;
  pointer-events: none;
}

.chat-sticker {
  display: block;
  max-height: 72px;
  max-width: min(120px, 100%);
  width: auto;
  height: auto;
  vertical-align: middle;
  margin: 0.15rem 0;
  border-radius: 6px;
}

.chat-panel__input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(7, 9, 12, 0.55);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
}

.chat-panel__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-panel__send {
  flex-shrink: 0;
  padding: 0.55rem 0.9rem;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: #0f172a;
  background: linear-gradient(165deg, var(--accent) 0%, #4f8cff 100%);
}

.chat-panel__send:hover {
  filter: brightness(1.06);
}

@media (max-width: 900px) {
  .page-layout {
    grid-template-columns: 1fr;
    padding-bottom: 2rem;
  }

  .chat-panel {
    position: relative;
    top: auto;
    height: min(calc(100vh - 6rem), 28rem);
    max-height: min(calc(100vh - 6rem), 28rem);
    height: min(calc(100dvh - 6rem), 28rem);
    max-height: min(calc(100dvh - 6rem), 28rem);
  }

  .chat-panel__head {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }

  .chat-panel__title {
    grid-column: 1;
  }

  .chat-panel__badge {
    grid-column: 2;
    grid-row: 1;
  }

  .chat-panel__nick {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  .chat-panel__nick-input {
    max-width: none;
  }
}

.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 158, 255, 0.22), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(168, 85, 247, 0.12), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(34, 211, 238, 0.08), transparent),
    var(--bg-deep);
}

.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;
}

.site-header {
  padding: 3rem 1.5rem 2rem;
  text-align: center;
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
}

.logo {
  margin: 0 0 0.5rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #a8c4ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 0 1.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.search-wrap {
  max-width: 440px;
  margin: 0 auto;
}

.search-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  width: 100%;
}

.search-row .search-input {
  flex: 1;
  min-width: 0;
}

.header-leave-msg-btn {
  flex-shrink: 0;
  padding: 0 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #0f172a;
  cursor: pointer;
  white-space: nowrap;
  background: linear-gradient(165deg, var(--accent) 0%, #4f8cff 100%);
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(108, 158, 255, 0.25);
  transition: filter 0.2s, transform 0.15s;
}

.header-leave-msg-btn:hover {
  filter: brightness(1.06);
}

.header-leave-msg-btn:active {
  transform: scale(0.98);
}

.search-input {
  width: 100%;
  padding: 0.85rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 0 0.15rem;
}

.toolbar-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.category-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.category-card {
  position: relative;
  display: block;
  padding: 1.35rem 1.25rem;
  text-decoration: none;
  color: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.category-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--card-tint, var(--accent-soft)) 0%, transparent 55%);
  opacity: 0.6;
  pointer-events: none;
}

.category-card:hover,
.category-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(108, 158, 255, 0.35);
  box-shadow: 0 12px 40px -12px var(--glow);
  outline: none;
}

.category-card:focus-visible {
  box-shadow: 0 0 0 2px var(--bg-deep), 0 0 0 4px var(--accent);
}

.card-icon {
  font-size: 1.75rem;
  line-height: 1;
  margin-bottom: 0.65rem;
  display: block;
}

.card-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.card-desc {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.card-meta {
  margin-top: 0.85rem;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.empty.hidden {
  display: none;
}

.site-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.site-footer code {
  font-size: 0.9em;
  color: var(--accent);
}

@media (max-width: 480px) {
  .site-header {
    padding-top: 2rem;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }
}
