:root {
  --bg0: #140e0a;
  --bg1: #2a1c12;
  --ink: #f4ebe3;
  --muted: #b9a593;
  --line: rgba(244, 235, 227, 0.12);
  --accent: #e8a04a;
  --accent-2: #c45c26;
  --mine: #3a2818;
  --theirs: rgba(255, 255, 255, 0.06);
  --danger: #e07a5f;
  --radius: 18px;
  --font-display: "Outfit", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
  --vv-offset-top: 0px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg0);
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(232, 160, 74, 0.22), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 92, 38, 0.28), transparent 50%),
    linear-gradient(160deg, #1a120c 0%, #0f0b08 55%, #1c1410 100%);
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23f4ebe3' opacity='0.15'/%3E%3C/svg%3E");
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.screen {
  height: 100%;
}

/* —— Login —— */
.login-screen {
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade-in 0.5s ease both;
}

.login-panel {
  width: min(420px, 100%);
  padding: 40px 32px 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(165deg, rgba(42, 28, 18, 0.85), rgba(20, 14, 10, 0.92));
  backdrop-filter: blur(12px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 6px;
  animation: rise 0.6s ease both;
}

.login-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 2.6rem);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 10px;
  animation: rise 0.6s 0.05s ease both;
}

.login-sub {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
  margin-bottom: 28px;
  animation: rise 0.6s 0.1s ease both;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field input,
.compose input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus,
.compose input:focus {
  border-color: rgba(232, 160, 74, 0.55);
  box-shadow: 0 0 0 3px rgba(232, 160, 74, 0.15);
}

.remember {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 20px;
  cursor: pointer;
  user-select: none;
}

.remember input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  border-radius: 14px;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  width: 100%;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1008;
  font-weight: 600;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1rem;
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn.ghost.on {
  background: rgba(232, 160, 74, 0.22);
  color: var(--accent);
}

.credit {
  margin-top: 22px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.credit strong {
  color: var(--accent);
  font-weight: 600;
}

/* —— Chat —— */
.chat-screen {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top top"
    "side main"
    "side compose";
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-offset-top);
  height: var(--app-height);
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  overflow: hidden;
  animation: fade-in 0.35s ease both;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 14, 10, 0.92);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 30% 30%, #f0c27a, transparent 45%),
    linear-gradient(145deg, #c45c26, #3a2214);
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent);
}

.brand-room {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.online-panel {
  grid-area: side;
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  background: rgba(0, 0, 0, 0.18);
  overflow: auto;
}

.online-panel h2 {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.online-panel ul {
  list-style: none;
  display: grid;
  gap: 8px;
}

.online-panel li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.online-panel li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6fbf73;
  box-shadow: 0 0 8px rgba(111, 191, 115, 0.6);
}

.messages {
  grid-area: main;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(520px, 88%);
  padding: 10px 14px;
  border-radius: 16px;
  animation: bubble 0.25s ease both;
  word-break: break-word;
}

.msg.system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 4px 8px;
  text-align: center;
}

.msg.theirs {
  align-self: flex-start;
  background: var(--theirs);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg.mine {
  align-self: flex-end;
  background: linear-gradient(160deg, #4a3220, var(--mine));
  border: 1px solid rgba(232, 160, 74, 0.2);
  border-bottom-right-radius: 6px;
}

.msg .meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.msg.mine .meta .nick {
  color: var(--accent);
}

.msg .text {
  line-height: 1.4;
  white-space: pre-wrap;
}

.compose {
  grid-area: compose;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(20, 14, 10, 0.92);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  z-index: 5;
}

.compose .send {
  width: 52px;
  flex-shrink: 0;
  font-size: 1.25rem;
  padding: 0;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bubble {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 720px) {
  .chat-screen {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main"
      "compose";
  }

  .online-panel {
    display: none;
  }
}
