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

:root {
  --bg: #1a1025;
  --surface: #241832;
  --surface2: #2e2040;
  --accent: #a855f7;
  --accent-dim: #7c3aed;
  --text: #f0e6ff;
  --text-dim: #9b8ab8;
  --bubble-mine: #7c3aed;
  --bubble-theirs: #2e2040;
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { height: 100%; position: relative; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ── Setup ── */
.setup-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 0.5rem;
}

.logo { font-size: 4rem; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline { color: var(--text-dim); font-size: 0.95rem; margin-bottom: 0.5rem; }
.credit { color: var(--text-dim); font-size: 0.7rem; opacity: 0.6; margin-bottom: 0.25rem; }
.version { color: var(--text-dim); font-size: 0.65rem; opacity: 0.4; margin-bottom: 1.5rem; }

.setup-form { width: 100%; max-width: 340px; }

.avatar-pick { text-align: center; margin-bottom: 1.5rem; }
.avatar-pick p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.75rem; }

.avatar-grid {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.avatar-option {
  font-size: 2rem;
  width: 3.2rem;
  height: 3.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
}
.avatar-option:hover { background: var(--surface2); }
.avatar-option.selected {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.3);
}

.room-section { display: flex; flex-direction: column; gap: 0.75rem; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ec4899);
  color: white;
}
.btn-primary:active { transform: scale(0.97); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  flex-shrink: 0;
  width: auto;
  padding: 0.85rem 1.2rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-dim);
  font-size: 0.8rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface2);
}

.join-row { display: flex; gap: 0.5rem; }

#room-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
#room-input::placeholder {
  color: var(--text-dim);
  letter-spacing: normal;
  text-transform: none;
}
#room-input:focus { outline: none; border-color: var(--accent); }

/* ── Chat ── */
#chat-screen {
  display: none;
  flex-direction: column;
  height: 100%;
}
#chat-screen.active { display: flex; }

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  flex-shrink: 0;
}

.header-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}

.header-info { display: flex; align-items: center; gap: 0.5rem; }
.partner-icon { font-size: 1.5rem; }
.room-code { font-size: 0.8rem; color: var(--text-dim); letter-spacing: 0.1em; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 70%;
  animation: pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.msg-mine { align-self: flex-end; }
.msg-theirs { align-self: flex-start; }

.msg-bubble {
  font-size: 2.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  line-height: 1.2;
  display: inline-block;
}

.msg-mine .msg-bubble {
  background: var(--bubble-mine);
  border-bottom-right-radius: 6px;
}
.msg-theirs .msg-bubble {
  background: var(--bubble-theirs);
  border-bottom-left-radius: 6px;
}

.msg-multi .msg-bubble { font-size: 1.8rem; }

.msg-time {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 2px;
  padding: 0 0.3rem;
}
.msg-mine .msg-time { text-align: right; }

.waiting-banner {
  text-align: center;
  padding: 0.75rem;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.hidden { display: none; }

/* Emoji Bar */
.emoji-bar {
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
}

.category-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 0;
  border-bottom: 1px solid var(--surface2);
}
.category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  font-size: 1.25rem;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
  border-bottom: 2px solid transparent;
}
.cat-tab.active {
  opacity: 1;
  border-bottom-color: var(--accent);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 0.5rem;
  max-height: 35vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.emoji-btn {
  font-size: 1.6rem;
  padding: 0.4rem;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
}
.emoji-btn:hover { background: var(--surface2); }
.emoji-btn:active { transform: scale(1.3); }

/* Toast */
.toast {
  position: fixed;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 100;
  animation: fadeout 2s forwards;
}
@keyframes fadeout {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Stamp (big emoji) reaction */
.stamp-preview {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 8rem;
  z-index: 50;
  pointer-events: none;
  animation: stamp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes stamp {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

@media (max-width: 380px) {
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
  .msg-bubble { font-size: 2.2rem; }
}
