:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #66706b;
  --line: #d8ddd3;
  --accent: #116b5f;
  --accent-strong: #0a4d45;
  --coral: #c94f3d;
  --gold: #f0ba43;
  --mint: #cfe8de;
  --shadow: 0 18px 45px rgba(32, 33, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(17, 107, 95, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(201, 79, 61, 0.08) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 18px;
  white-space: nowrap;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
  padding: 12px 14px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.18);
}

textarea {
  min-height: 52px;
  resize: vertical;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.join-view,
.chat-view {
  width: min(100%, 960px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.join-view {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1.1fr);
  overflow: hidden;
}

.brand-panel {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  background: var(--accent);
  color: #ffffff;
  padding: 32px;
}

.brand-mark {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background: var(--gold);
  color: #202124;
  font-size: 1.35rem;
  font-weight: 900;
}

.brand-panel h1,
.chat-header h1 {
  margin: 0;
  letter-spacing: 0;
}

.brand-panel h1 {
  font-size: clamp(2.1rem, 7vw, 4.2rem);
  line-height: 0.95;
}

.brand-panel p,
.eyebrow {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-weight: 700;
}

.join-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 32px;
}

.join-form label,
.avatar-controls label,
.admin-panel label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.avatar-picker {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 6px;
}

.avatar-preview {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--gold);
  color: #202124;
  font-size: 1.3rem;
  font-weight: 900;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-controls {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.avatar-controls input {
  min-width: 0;
  padding: 10px;
}

.clear-avatar-button {
  width: fit-content;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--coral);
  font-weight: 700;
}

.chat-view {
  height: min(820px, calc(100vh - 48px));
  min-height: 520px;
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
  overflow: hidden;
}

.is-hidden {
  display: none;
}

.chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
}

.users-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: #fbfcf8;
}

.users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.users-header h2 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 1rem;
  letter-spacing: 0;
}

.user-count {
  min-width: 34px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 900;
  padding: 6px 9px;
  text-align: center;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  padding: 14px;
}

.user-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--gold);
  color: #202124;
  font-size: 0.78rem;
  font-weight: 900;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.you-pill {
  border-radius: 999px;
  background: #eef3ee;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  padding: 4px 7px;
}

.users-empty {
  margin: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  padding: 14px 18px;
}

.users-empty.is-hidden {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 18px 22px;
}

.chat-header h1 {
  font-size: 1.6rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--mint);
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 8px 12px;
  text-align: center;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.secondary-button:hover {
  background: #f1f3ee;
}

.message-panel {
  position: relative;
  overflow: hidden;
}

.rain-effect {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.rain-drop {
  position: absolute;
  top: -24px;
  left: var(--rain-x);
  width: 2px;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(17, 107, 95, 0), rgba(17, 107, 95, 0.72));
  opacity: 0;
  transform: translate3d(0, 0, 0);
  animation: rain-drop-fall var(--rain-duration) linear forwards;
  animation-delay: var(--rain-delay);
}

.confetti-effect {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: 4%;
  left: 50%;
  width: var(--confetti-size);
  height: calc(var(--confetti-size) * 0.55);
  border-radius: 2px;
  background: var(--confetti-color);
  opacity: 0;
  transform: translate3d(-50%, 0, 0) rotate(0deg);
  animation: confetti-burst var(--confetti-duration) cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  animation-delay: var(--confetti-delay);
}

.matrix-effect {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background: rgba(0, 8, 5, 0.93);
  pointer-events: none;
}

.matrix-effect canvas {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 5px rgba(0, 255, 65, 0.45));
}

.death-effect {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0078d7;
  color: #ffffff;
  font-family: "Segoe UI", Arial, sans-serif;
  pointer-events: none;
}

.death-effect-content {
  width: min(760px, 82vw);
  padding: 8vh 0;
}

.death-effect-face {
  margin-bottom: 2.5vh;
  font-size: clamp(72px, 12vw, 132px);
  font-weight: 300;
  line-height: 0.9;
}

.death-effect-message {
  max-width: 700px;
  margin: 0 0 2.5vh;
  font-size: clamp(26px, 4vw, 46px);
  font-weight: 300;
  line-height: 1.18;
}

.death-effect-detail,
.death-effect-progress,
.death-effect-stop-code,
.death-effect-countdown {
  margin: 1.6vh 0 0;
  font-size: clamp(15px, 2vw, 21px);
  font-weight: 400;
  line-height: 1.45;
}

.death-effect-progress {
  margin-top: 4vh;
}

.death-effect-stop-code {
  margin-top: 8vh;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(12px, 1.5vw, 16px);
}

.death-effect-countdown {
  margin-top: 2vh;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .matrix-effect {
    opacity: 0.82;
  }

  .death-effect-content {
    transition: none;
  }
}

.message-list {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  overflow-y: auto;
  padding: 18px 22px 24px;
}

.message-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: start;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--gold);
  color: #202124;
  font-weight: 900;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-bubble {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
}

.message-bubble-action {
  background: #fbfcf8;
  border-color: rgba(17, 107, 95, 0.24);
}

.message-item-action .message-text,
.message-item-emote .message-text {
  color: var(--accent-strong);
  font-weight: 850;
}

.app-version {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
}

.brand-panel .app-version {
  color: rgba(255, 255, 255, 0.72);
}

.message-item-history .message-bubble {
  background: #fbfcf8;
  border-style: dashed;
}

.message-item-history .message-text {
  font-size: 0.86rem;
  color: var(--muted);
}

.message-item-history .message-text::first-line {
  font-weight: 850;
  color: var(--accent-strong);
}

.message-bubble-typing {
  background: #fbfcf8;
  border-style: dashed;
  padding: 14px 12px;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
}

.message-name {
  font-weight: 900;
}

.message-time,
.pending-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

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

.message-text a {
  color: var(--teal);
  text-decoration: underline;
}

.avatar.is-emoting {
  transform-origin: 50% 100%;
  will-change: transform;
}

.avatar.is-wave {
  animation: wave-avatar 900ms ease-in-out 2;
}

.avatar.is-cheer {
  animation: cheer-avatar 760ms ease-in-out 2;
}

.avatar.is-laugh {
  animation: laugh-avatar 620ms ease-in-out 3;
}

.avatar.is-dance {
  animation: dance-avatar 780ms ease-in-out 3;
}

.avatar.is-dance2 {
  animation: dance-two-avatar 720ms ease-in-out 3;
}

.avatar.is-dance3 {
  animation: dance-three-avatar 840ms ease-in-out 3;
}

.avatar.is-rain {
  animation: rain-avatar 900ms ease-in-out 2;
}

.avatar.is-confetti {
  animation: confetti-avatar 900ms ease-in-out 2;
}

@keyframes rain-drop-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -30px, 0);
  }

  12% {
    opacity: 0.9;
  }

  90% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--rain-drift), var(--rain-distance), 0);
  }
}

@keyframes confetti-burst {
  0% {
    opacity: 0;
    transform: translate3d(-50%, 0, 0) rotate(0deg) scale(0.7);
  }

  12% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--confetti-x), var(--confetti-y), 0)
      rotate(var(--confetti-rotate)) scale(1);
  }
}

@keyframes confetti-avatar {
  0%,
  100% {
    transform: rotate(0deg) translateY(0) scale(1);
  }

  25% {
    transform: rotate(-10deg) translateY(-5px) scale(1.08);
  }

  50% {
    transform: rotate(12deg) translateY(-8px) scale(1.12);
  }

  75% {
    transform: rotate(-8deg) translateY(-3px) scale(1.05);
  }
}

@keyframes wave-avatar {
  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-12deg) translateY(-2px);
  }

  50% {
    transform: rotate(14deg) translateY(-3px);
  }

  75% {
    transform: rotate(-8deg) translateY(-1px);
  }
}

@keyframes cheer-avatar {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  40% {
    transform: translateY(-10px) scale(1.06) rotate(-5deg);
  }

  70% {
    transform: translateY(-4px) scale(1.03) rotate(5deg);
  }
}

@keyframes laugh-avatar {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
  }

  25% {
    transform: translateX(-2px) rotate(-5deg);
  }

  50% {
    transform: translateX(2px) rotate(5deg);
  }

  75% {
    transform: translateX(-1px) rotate(-3deg);
  }
}

@keyframes dance-avatar {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
  }

  25% {
    transform: translateX(-5px) rotate(-8deg);
  }

  50% {
    transform: translateY(-5px) rotate(7deg);
  }

  75% {
    transform: translateX(5px) rotate(9deg);
  }
}

@keyframes dance-two-avatar {
  0%,
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }

  30% {
    transform: translateY(-7px) scale(1.05) rotate(8deg);
  }

  60% {
    transform: translateY(3px) scale(0.96) rotate(-8deg);
  }
}

@keyframes dance-three-avatar {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }

  20% {
    transform: rotate(-12deg) scale(1.03);
  }

  45% {
    transform: translateY(-7px) rotate(12deg) scale(1.08);
  }

  70% {
    transform: rotate(-7deg) scale(0.98);
  }
}

@keyframes rain-avatar {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  30% {
    transform: translateY(3px) rotate(-4deg);
  }

  60% {
    transform: translateY(-2px) rotate(4deg);
  }
}

.delete-button {
  min-width: 76px;
  min-height: 36px;
  border: 1px solid rgba(201, 79, 61, 0.36);
  background: #fff7f5;
  color: var(--coral);
  padding: 0 12px;
}

.delete-button:hover {
  background: #ffe9e4;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.empty-state.is-hidden {
  display: none;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 22px;
}

.admin-panel {
  border-top: 1px solid var(--line);
  padding: 12px 22px 16px;
}

.admin-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 900;
}

.admin-panel input {
  max-width: 240px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  margin: 0;
  border-radius: 8px;
  background: #202124;
  color: #ffffff;
  font-weight: 800;
  opacity: 0;
  padding: 12px 14px;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

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

  .brand-panel {
    min-height: 220px;
  }

  .field-row,
  .composer {
    grid-template-columns: 1fr;
  }

  .chat-view {
    height: calc(100vh - 24px);
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .users-panel {
    max-height: 160px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .user-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .user-item {
    min-width: 160px;
  }

  .users-empty {
    display: none;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .message-item {
    grid-template-columns: 36px 1fr;
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .delete-button {
    grid-column: 2;
    justify-self: start;
  }
}

@media (max-width: 480px) {
  .avatar-picker {
    grid-template-columns: 1fr;
  }
}
