:root {
  --bg: #050505;
  --bg-soft: #0a0b0c;
  --panel: rgba(12, 13, 14, 0.9);
  --panel-muted: rgba(16, 17, 18, 0.72);
  --line: rgba(226, 232, 230, 0.09);
  --line-soft: rgba(226, 232, 230, 0.055);
  --text: #e8e5df;
  --text-soft: #c9c6bf;
  --muted: #85827b;
  --dim: #5f5e59;
  --input: rgba(5, 6, 7, 0.78);
  --cyan: #b8edf3;
  --cyan-faint: rgba(110, 220, 238, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -18%, rgba(90, 115, 122, 0.13), transparent 34rem),
    radial-gradient(circle at 15% 92%, rgba(54, 64, 70, 0.1), transparent 28rem),
    linear-gradient(180deg, #08090a 0%, var(--bg) 54%, #020202 100%);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(140, 230, 240, 0.026), transparent),
    radial-gradient(circle at 50% 50%, transparent 0, rgba(0, 0, 0, 0.34) 72%);
  opacity: 0.9;
}

button,
input {
  font: inherit;
}

button {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.018);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  transition:
    border-color 220ms ease,
    color 220ms ease,
    background 220ms ease,
    box-shadow 220ms ease,
    transform 220ms ease;
}

button:hover:not(:disabled),
button:focus-visible {
  color: var(--text);
  border-color: rgba(184, 237, 243, 0.28);
  background: rgba(184, 237, 243, 0.035);
  box-shadow: 0 0 24px rgba(95, 210, 226, 0.07);
  outline: none;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  color: var(--dim);
  border-color: var(--line-soft);
}

.shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 44px) 18px;
  position: relative;
  z-index: 1;
}

.chat {
  width: min(100%, 780px);
  height: min(760px, calc(100vh - 64px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(17, 18, 19, 0.92), rgba(7, 8, 9, 0.94)),
    var(--panel);
  border: 1px solid var(--line);
  box-shadow:
    0 28px 96px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.018) inset,
    0 0 52px rgba(70, 210, 225, 0.035);
}

.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(117, 225, 240, 0.05), transparent 18%, transparent 82%, rgba(117, 225, 240, 0.035)),
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.035), transparent 20rem);
}

.topbar,
.messages,
.typing-indicator,
.composer,
.actions {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.12);
}

h1 {
  margin: 0 0 8px;
  color: #f0eee9;
  font-size: clamp(1.55rem, 4vw, 2.15rem);
  font-weight: 500;
  line-height: 1.05;
}

.topbar p,
.counter,
.system,
.typing-indicator {
  font-family: "IBM Plex Mono", Consolas, monospace;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.topbar p {
  min-height: 1em;
  margin: 0;
  transition: color 240ms ease, opacity 240ms ease;
}

.counter {
  min-width: 84px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  padding-top: 3px;
}

.counter span:first-child {
  color: var(--text-soft);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.98rem;
  font-weight: 500;
}

.messages {
  overflow-y: auto;
  padding: clamp(24px, 4vw, 34px) 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.012), transparent 7rem),
    rgba(0, 0, 0, 0.08);
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
  scroll-behavior: smooth;
}

.system,
.message {
  animation: fadeIn 260ms ease both;
}

.system {
  max-width: 58ch;
  margin: 0 0 18px;
}

.system.searching,
.system.disconnect {
  width: fit-content;
  max-width: 100%;
  padding: 7px 0 7px 12px;
  border-left: 1px solid rgba(184, 237, 243, 0.22);
}

.system.searching {
  color: #a9bbb9;
  animation: fadeIn 260ms ease both, pulseSearch 2.8s ease-in-out infinite;
}

.system.disconnect {
  color: #8f918c;
}

.message {
  max-width: min(76%, 540px);
  margin: 0 0 14px;
  padding: 10px 12px 11px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.022);
  border: 1px solid rgba(255, 255, 255, 0.045);
  border-radius: 6px;
  line-height: 1.62;
  font-size: 0.96rem;
  font-weight: 400;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message::before {
  display: block;
  margin-bottom: 4px;
  color: var(--dim);
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.68rem;
  line-height: 1.2;
}

.message.mine {
  margin-left: auto;
  color: #e9e7e1;
  background: rgba(255, 255, 255, 0.032);
  border-color: rgba(184, 237, 243, 0.075);
}

.message.mine::before {
  content: "you";
}

.message.stranger::before {
  content: "stranger";
}

.typing-indicator {
  min-height: 25px;
  padding: 0 28px 10px;
  color: #94aaa9;
  opacity: 0.82;
}

.typing-indicator span {
  animation: blink 1.5s infinite both;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 180ms;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 360ms;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 28px 18px;
  border-top: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.16);
}

.composer input {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
  line-height: 1.35;
  transition:
    border-color 220ms ease,
    background 220ms ease,
    box-shadow 220ms ease;
}

.composer input::placeholder {
  color: var(--dim);
}

.composer input:focus {
  border-color: rgba(184, 237, 243, 0.32);
  background: rgba(7, 8, 9, 0.92);
  box-shadow: 0 0 0 3px rgba(110, 220, 238, 0.045);
}

.composer input:disabled {
  color: var(--dim);
}

.composer button {
  min-width: 78px;
  padding: 0 15px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 28px 24px;
  background: rgba(0, 0, 0, 0.16);
}

.actions button {
  min-height: 39px;
  padding: 9px 13px;
}

.report-button {
  margin-right: auto;
  color: #9d9a93;
}

.report-button:hover:not(:disabled),
.report-button:focus-visible {
  color: #d9d5cc;
  border-color: rgba(232, 229, 223, 0.18);
  background: rgba(255, 255, 255, 0.028);
  box-shadow: none;
}

body[data-mode="waiting"] #statusText {
  color: #a9bbb9;
  animation: pulseSearch 2.8s ease-in-out infinite;
}

body[data-mode="chat"] #statusText {
  color: #b9c8c6;
}

body[data-mode="idle"] #statusText {
  color: var(--muted);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  0%, 80%, 100% {
    opacity: 0.16;
  }
  40% {
    opacity: 1;
  }
}

@keyframes pulseSearch {
  0%, 100% {
    opacity: 0.58;
  }
  50% {
    opacity: 0.95;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 680px) {
  body {
    overflow: hidden;
  }

  .shell {
    padding: 0;
    place-items: stretch;
  }

  .chat {
    width: 100%;
    height: 100vh;
    min-height: 0;
    border: 0;
    box-shadow: none;
  }

  .topbar,
  .messages,
  .composer,
  .actions {
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar {
    gap: 16px;
    padding-top: 20px;
    padding-bottom: 17px;
  }

  .counter {
    min-width: 70px;
  }

  .messages {
    padding-top: 22px;
    padding-bottom: 22px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding-top: 14px;
  }

  .composer button,
  .actions button {
    width: 100%;
    min-height: 45px;
  }

  .actions {
    flex-direction: column;
    padding-bottom: 18px;
  }

  .report-button {
    margin-right: 0;
  }

  .message {
    max-width: 100%;
    font-size: 0.95rem;
  }
}

@media (max-width: 380px) {
  .topbar {
    flex-direction: column;
  }

  .counter {
    align-items: flex-start;
  }
}
