:root {
  --bg: #0a0b0e;
  --bg-soft: radial-gradient(1200px 600px at 50% -10%, rgba(99, 102, 241, 0.12), transparent 60%), #0a0b0e;
  --surface: #15171d;
  --surface-2: #1c1f27;
  --border: #262a34;
  --text: #eef0f4;
  --text-dim: #8b90a0;
  --text-faint: #565c6c;
  --accent-1: #6366f1;
  --accent-2: #a855f7;
  --accent-gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --danger: #ff6b6b;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-soft);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2e38; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #363b47; }

/* Gate */
.gate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-soft);
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.gate-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-bottom: 4px;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}
.gate-card h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff, #b9bcc7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gate-card .hint {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}
.field { position: relative; }
.gate-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #0d0e12;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.gate-card input::placeholder { color: var(--text-faint); }
.gate-card input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.gate-card button {
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-gradient);
  color: white;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}
.gate-card button:hover { filter: brightness(1.08); box-shadow: 0 8px 22px rgba(99, 102, 241, 0.4); }
.gate-card button:active { transform: scale(0.98); }
.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

/* Chat */
.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(21, 23, 29, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}
.brand-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.header-hint {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 78%;
  margin-top: 10px;
  animation: pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.msg-row.grouped { margin-top: 2px; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.theirs { align-self: flex-start; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: 0 0 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  margin-bottom: 2px;
}
.avatar.spacer { visibility: hidden; }

.bubble-stack { display: flex; flex-direction: column; min-width: 0; }
.sender {
  font-size: 11.5px;
  font-weight: 600;
  opacity: 0.75;
  margin: 0 2px 3px;
}
.msg-row.mine .sender { text-align: right; }

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.msg-row.mine .bubble {
  background: var(--accent-gradient);
  color: white;
  border-bottom-right-radius: 5px;
}
.msg-row.theirs .bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg-row.mine.grouped .bubble { border-top-right-radius: 5px; }
.msg-row.theirs.grouped .bubble { border-top-left-radius: 5px; }

.bubble.emoji-big {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 2px 4px;
  font-size: 46px;
  line-height: 1.15;
  animation: emojiPop 0.45s cubic-bezier(0.17, 0.89, 0.32, 1.49);
}
@keyframes emojiPop {
  0% { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  60% { opacity: 1; transform: scale(1.15) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.floating-heart {
  position: fixed;
  bottom: 90px;
  z-index: 999;
  pointer-events: none;
  animation-name: floatUp;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0) translateX(0) scale(0.6); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-70vh) translateX(var(--drift, 12px)) scale(1.1); }
}

.kiss-mark {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  animation: kissPop 1.1s ease-out forwards;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}
@keyframes kissPop {
  0% { opacity: 0; transform: scale(0.2) rotate(var(--rot, -15deg)); }
  35% { opacity: 1; transform: scale(1.35) rotate(var(--rot, -15deg)); }
  55% { transform: scale(1) rotate(calc(var(--rot, -15deg) * -0.4)); }
  100% { opacity: 0; transform: scale(0.85) rotate(0deg) translateY(-30px); }
}

.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble img, .bubble video {
  max-width: 260px;
  max-height: 320px;
  border-radius: 10px;
  display: block;
}
.bubble.media { padding: 4px; }

.timestamp {
  font-size: 10.5px;
  color: var(--text-faint);
  margin: 3px 4px 0;
}
.msg-row.mine .timestamp { text-align: right; }

.system-msg {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-faint);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  margin: 10px 0;
}

.emoji-bar {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: rgba(21, 23, 29, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  scrollbar-width: none;
}
.emoji-bar::-webkit-scrollbar { display: none; }
.emoji-chip {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.emoji-chip:hover {
  background: #23262f;
  border-color: rgba(168, 85, 247, 0.4);
  transform: translateY(-2px) scale(1.12);
}
.emoji-chip:active { transform: scale(0.9); }

.send-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: rgba(21, 23, 29, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s, filter 0.15s;
}
.file-btn {
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.file-btn:hover { color: var(--text); background: #23262f; }
.send-form input[type="text"] {
  flex: 1;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: #0d0e12;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.send-form input[type="text"]::placeholder { color: var(--text-faint); }
.send-form input[type="text"]:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.send-btn {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(0.94); }

@media (max-width: 480px) {
  .msg-row { max-width: 86%; }
  .bubble img, .bubble video { max-width: 200px; }
}
