:root {
  --bg: #050505;
  --fg: #f3f3f3;
  --muted: rgba(243, 243, 243, 0.55);
  --line: rgba(255, 255, 255, 0.1);
  --panel: rgba(14, 14, 14, 0.88);
  --max: 38rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --discord: #5865f2;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  min-height: 100dvh;
  font-family: Sora, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 55% 45% at 50% 28%, rgba(255, 255, 255, 0.07), transparent 68%),
    radial-gradient(ellipse 80% 55% at 80% 0%, rgba(255, 255, 255, 0.03), transparent 50%),
    radial-gradient(ellipse 100% 70% at 50% 110%, rgba(0, 0, 0, 0.9), transparent 55%),
    #050505;
}

/* ---------- Mute (top-right) ---------- */
.mute {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 45;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: #121212;
  color: #e0e0e0;
  cursor: pointer;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms var(--ease),
    color 160ms ease;
}

.mute:hover {
  background: #1a1a1a;
  border-color: rgba(255, 255, 255, 0.14);
  color: #f5f5f5;
}

.mute:active {
  transform: scale(0.96);
}

.mute:focus-visible {
  outline: 2px solid rgba(224, 224, 224, 0.55);
  outline-offset: 3px;
}

.mute__icon {
  width: 22px;
  height: 22px;
  display: none;
}

.mute:not(.is-muted) .mute__icon--on,
.mute.is-muted .mute__icon--off {
  display: block;
}

.mute.is-muted {
  color: #9a9a9a;
}

/* ---------- Discord ---------- */
.discord {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  max-width: 118px;
  padding: 0 12px 0 10px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--discord);
  color: #fff;
  text-decoration: none;
  font: 600 12px/1 Sora, "Segoe UI", sans-serif;
  box-shadow: 0 10px 24px rgba(88, 101, 242, 0.28);
  transition:
    transform 160ms var(--ease),
    filter 160ms ease;
}

.discord svg {
  width: 15px;
  height: 15px;
  display: block;
  flex: 0 0 15px;
}

.discord span {
  white-space: nowrap;
}

.discord:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.discord:active {
  transform: translateY(0);
}

.discord:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.15rem;
  padding: clamp(1.1rem, 3.5vw, 2.4rem);
  padding-top: 4.25rem;
  padding-bottom: 4.75rem;
}

.portrait {
  position: relative;
  margin: 0;
  width: min(100%, var(--max));
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  animation: rise 900ms var(--ease) 60ms forwards;
}

.portrait__glow {
  position: absolute;
  inset: 8% 12% auto;
  height: 70%;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.12), transparent 70%);
  filter: blur(28px);
  pointer-events: none;
  z-index: 0;
}

.portrait img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  max-height: min(52dvh, 560px);
  object-fit: contain;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
  filter: contrast(1.06) brightness(0.98);
  border-radius: 0.35rem;
}

.embed {
  display: block;
  width: min(100%, var(--max));
  height: 10rem;
  margin: 0;
  padding: 0.85rem 1rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  background: rgba(0, 0, 0, 0.42);
  color: rgba(243, 243, 243, 0.82);
  font: 400 0.82rem/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  opacity: 0;
  transform: translateY(10px);
  animation: rise 900ms var(--ease) 160ms forwards;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.embed::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* ---------- Chat ---------- */
.chat {
  /* Fixed panel: ~16:10 ratio at content width (608×380) */
  --chat-w: min(100%, var(--max));
  --chat-h: 22.5rem;
  width: var(--chat-w);
  height: var(--chat-h);
  min-width: 0;
  min-height: var(--chat-h);
  max-height: var(--chat-h);
  flex: 0 0 var(--chat-h);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background:
    linear-gradient(180deg, rgba(22, 22, 22, 0.94), rgba(8, 8, 8, 0.98));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 22px 50px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  animation: rise 900ms var(--ease) 250ms forwards;
}

.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.chat__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.chat__dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #6dff8a;
  box-shadow: 0 0 0 4px rgba(109, 255, 138, 0.12);
  animation: blink 2.2s ease-in-out infinite;
}

.chat__title {
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: lowercase;
}

.chat__meta {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.chat__you,
.chat__status {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

.chat__you {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 10rem;
  font-variant-numeric: tabular-nums;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat__status[data-state="online"] {
  color: #8dffa3;
}

.chat__status[data-state="offline"] {
  color: #ffb086;
}

.chat__body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat__log {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: auto;
}

.chat__log::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.chat__jump {
  position: absolute;
  left: 50%;
  bottom: 0.65rem;
  transform: translateX(-50%);
  z-index: 2;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.92);
  color: #f0f0f0;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition:
    transform 160ms var(--ease),
    background 160ms ease,
    border-color 160ms ease;
}

.chat__jump:hover {
  background: rgba(32, 32, 32, 0.96);
  border-color: rgba(255, 255, 255, 0.24);
  transform: translateX(-50%) translateY(-1px);
}

.chat__jump[hidden] {
  display: none !important;
}

.chat__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.chat__msg {
  display: grid;
  grid-template-columns: minmax(5.8rem, auto) 1fr;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  padding: 0.45rem 0.55rem;
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.86rem;
  line-height: 1.4;
}

.chat__msg.is-me {
  background: rgba(255, 255, 255, 0.045);
}

.chat__msg.is-me .chat__user {
  color: #d5dcff;
}

.chat__user {
  color: rgba(243, 243, 243, 0.42);
  font-size: 0.7rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.chat__text {
  color: var(--fg);
  word-break: break-word;
}

.chat__sys {
  font-size: 0.72rem;
  color: rgba(243, 243, 243, 0.38);
  text-align: center;
  padding: 0.2rem 0;
}

.chat__form {
  display: flex;
  gap: 0.55rem;
  padding: 0.75rem;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
}

.chat__input {
  flex: 1;
  min-width: 0;
  height: 2.45rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.035);
  color: var(--fg);
  padding: 0 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.chat__input::placeholder {
  color: rgba(243, 243, 243, 0.32);
}

.chat__input:focus {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.055);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.chat__send {
  appearance: none;
  height: 2.45rem;
  padding: 0 1.05rem;
  border: 0;
  border-radius: 0.8rem;
  background: #efefef;
  color: #111;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition:
    filter 160ms ease,
    transform 160ms var(--ease);
}

.chat__send:hover {
  filter: brightness(0.95);
}

.chat__send:active {
  transform: scale(0.97);
}

/* ---------- Gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms var(--ease);
}

.gate.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.gate[hidden] {
  display: none !important;
}

.gate__btn {
  appearance: none;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(12, 12, 12, 0.9);
  color: var(--fg);
  border-radius: 999px;
  padding: 1rem 1.75rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms var(--ease);
}

.gate__btn:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(20, 20, 20, 0.96);
  transform: scale(1.02);
}

.gate__pulse {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.22);
  animation: pulse 2s ease-out infinite;
  pointer-events: none;
}

.gate__label {
  position: relative;
  z-index: 1;
}

@keyframes rise {
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.22);
  }
  70% {
    box-shadow: 0 0 0 18px rgba(255, 255, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@media (max-width: 560px) {
  .chat {
    --chat-h: 18.75rem; /* 300px — same ratio feel on narrow screens */
  }

  .chat__msg {
    grid-template-columns: 1fr;
    gap: 0.18rem;
  }

  .chat__you {
    display: none;
  }

  .mute {
    top: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .portrait,
  .embed,
  .chat,
  .gate__pulse,
  .chat__dot {
    animation: none;
  }

  .portrait,
  .embed,
  .chat {
    opacity: 1;
    transform: none;
  }
}
