/* ============================================
   Roomz — Complete PWA Stylesheet
   ============================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0a0a1a;
  --card: #1a1a2e;
  --border: #2a2a3e;
  --text: #e2e8f0;
  --muted: #64748b;
  --primary: #8b5cf6;
  --primary-dim: rgba(139, 92, 246, .15);
  --secondary: #ec4899;
  --secondary-dim: rgba(236, 72, 153, .15);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --gradient: linear-gradient(135deg, var(--primary), var(--secondary));
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  height: 100vh;
  height: -webkit-fill-available;
  height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
#app {
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  height: var(--app-height, 100dvh);
}

a { color: var(--primary); text-decoration: none; }
img { display: block; max-width: 100%; }
input, textarea, button, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---------- Layout ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 100vw;
  position: relative;
  overflow: hidden;
}

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  width: 100%;
}
.view.active {
  display: flex;
}

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}
.header-logo {
  height: 32px;
  width: 32px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}
.view-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.view-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ---------- Tab Bar ---------- */
.tab-bar {
  display: flex;
  background: var(--card);
  border-top: none;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Kill any space below tab bar on iOS PWA */
html {
  background: var(--card);
}
/* Hide tab bar when in chat — toggled by JS */
.tab-bar.hidden-in-chat {
  display: none !important;
}
.tab-bar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .65rem;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s;
  min-height: 52px;
  position: relative;
}
.tab-bar-btn .tab-icon {
  font-size: 1.35rem;
  line-height: 1;
}
.tab-bar-btn.active {
  color: var(--primary);
}
.tab-bar-btn.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 3px;
  background: var(--gradient);
  border-radius: 0 0 3px 3px;
}
.tab-bar-btn .badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 20px);
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 0 5px;
  line-height: 1;
}

/* ---------- Splash Screen ---------- */
#splash-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 9999;
  transition: opacity .4s, visibility .4s;
}
#splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#splash-screen .logo {
  font-size: 4rem;
  animation: pulse-glow 2s ease-in-out infinite;
}
#splash-screen h1 {
  font-size: 2rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-glow {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(139,92,246,.4)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 20px rgba(139,92,246,.7)); }
}

/* ---------- Onboarding ---------- */
#onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 8000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#onboarding.active { display: flex; }
#onboarding .onboarding-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
}
#onboarding .onboarding-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#onboarding .onboarding-card p {
  color: var(--muted);
  margin-bottom: 24px;
}

/* ---------- Forms ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  margin-bottom: 16px;
}
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  font-size: 16px !important; /* Prevent iOS auto-zoom */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .95rem;
  transition: border-color .2s, box-shadow .2s;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
  outline: none;
}
.form-input::placeholder { color: var(--muted); }
textarea.form-input {
  resize: vertical;
  min-height: 80px;
}
select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s, opacity .2s;
  min-height: 44px;
  user-select: none;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(139,92,246,.35);
}
.btn-primary:hover { box-shadow: 0 6px 24px rgba(139,92,246,.5); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); }

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
}

.btn-block { width: 100%; }

/* ---------- Avatars ---------- */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}
.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-xl { width: 96px; height: 96px; }
.avatar-wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--primary-dim);
  color: var(--primary);
}

/* ---------- Status Dots ---------- */
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--card);
  position: absolute;
  bottom: 0;
  right: 0;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--muted); }

/* ---------- Badges ---------- */
.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  border-radius: 99px;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-tag.admin { background: var(--secondary-dim); color: var(--secondary); }
.badge-tag.mod { background: var(--primary-dim); color: var(--primary); }

/* ---------- Room List ---------- */
.room-list {
  display: flex;
  flex-direction: column;
}
/* ---------- Room Cards (Compact Neon) ---------- */
.room-card {
  position: relative;
  padding: 10px 14px;
  margin: 4px 10px;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(26,26,46,0.9), rgba(20,20,40,0.95));
  border: 1px solid rgba(139,92,246,0.1);
  cursor: pointer;
  transition: all .2s ease;
  overflow: hidden;
}
.room-card:active { transform: scale(0.98); }
.room-card:hover {
  border-color: rgba(139,92,246,0.3);
  box-shadow: 0 0 16px rgba(139,92,246,0.08);
}
.room-card.room-active {
  border-color: rgba(139,92,246,0.25);
  box-shadow: 0 0 18px rgba(139,92,246,0.08);
}
.room-card.room-fav { border-color: rgba(236,72,153,0.2); }
.room-card.room-fav:hover { border-color: rgba(236,72,153,0.4); }

/* Glow bar */
.room-glow {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient);
  animation: glowPulse 2s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; box-shadow: 0 0 10px rgba(139,92,246,0.5); }
}

/* Card layout: icon left, rows right */
.room-card {
  display: flex;
  align-items: center;
  gap: 10px;
}
.room-card-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.room-card-content {
  flex: 1;
  min-width: 0;
}
.room-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-card-name {
  flex: 1;
  font-weight: 700;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-stat-online {
  font-size: .68rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.room-stat-online::before {
  content: '';
  width: 5px; height: 5px;
  background: var(--muted);
  border-radius: 50%;
}
.room-stat-online.live {
  color: var(--success);
  font-weight: 600;
}
.room-stat-online.live::before {
  background: var(--success);
  box-shadow: 0 0 5px var(--success);
  animation: liveDot 1.5s ease-in-out infinite;
}
@keyframes liveDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Row 2: preview + time */
.room-row2 {
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.room-row2-time {
  float: right;
  color: var(--muted);
  font-size: .68rem;
  margin-left: 8px;
}

/* ---------- Chat Messages ---------- */
.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header .back-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title {
  font-weight: 700;
  font-size: 1rem;
}
.chat-header-sub {
  font-size: .75rem;
  color: var(--muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overscroll-behavior-y: contain;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  padding: 4px 0;
  animation: msg-in .25s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg .avatar { align-self: flex-end; }
.msg-body { min-width: 0; flex: 1; }
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg-nick {
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
}
.msg-nick:hover { text-decoration: underline; }
.msg-time {
  font-size: .7rem;
  color: var(--muted);
}
.msg-text {
  font-size: .92rem;
  line-height: 1.5;
  word-break: break-word;
}
.msg-text .mention {
  color: #fbbf24;
  font-weight: 600;
  cursor: pointer;
}
.msg-reply {
  border-left: 3px solid var(--primary);
  padding: 4px 10px;
  margin-bottom: 4px;
  background: var(--primary-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .82rem;
  color: var(--muted);
  cursor: pointer;
}
.msg-reactions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.msg-reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: .78rem;
  cursor: pointer;
  transition: border-color .15s;
}
.msg-reaction:hover { border-color: var(--primary); }
.msg-reaction.mine { border-color: var(--primary); background: var(--primary-dim); }
.msg-image {
  max-width: 280px;
  border-radius: var(--radius);
  margin-top: 4px;
}
.msg-audio {
  margin-top: 4px;
}
.msg-audio audio { display: none; }

/* Custom audio player */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(135deg, rgba(139,92,246,0.12), rgba(236,72,153,0.08));
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: 24px;
  max-width: 280px;
  min-width: 200px;
  user-select: none;
}
.audio-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 0 10px rgba(139,92,246,0.3);
}
.audio-play-btn:active {
  transform: scale(0.92);
}
.audio-play-btn.playing {
  box-shadow: 0 0 16px rgba(139,92,246,0.5);
}
.audio-progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.audio-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.audio-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient);
  border-radius: 2px;
  transition: width .1s linear;
}
.audio-time {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.voice-msg-btn {
  position: relative;
}
.voice-msg-btn.recording {
  color: #ef4444 !important;
  animation: voicePulse 1s infinite;
}

/* Reaction picker */
.reaction-picker {
  display: none;
  position: absolute;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 8px;
  gap: 2px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.reaction-picker.visible { display: flex; }
.reaction-picker button {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.reaction-picker button:hover { background: var(--primary-dim); }

/* System message */
.msg-system {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  padding: 8px 0;
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 16px;
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
  min-height: 24px;
  flex-shrink: 0;
}

/* Chat input */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border-top: none;
  flex-shrink: 0;
}
.chat-input-bar .emoji-btn {
  background: rgba(139,92,246,0.08);
  border: 1px solid rgba(139,92,246,0.15);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: all .2s ease;
  flex-shrink: 0;
}
.chat-input-bar .emoji-btn:hover {
  background: rgba(139,92,246,0.18);
  border-color: rgba(139,92,246,0.35);
  transform: translateY(-1px);
}
.chat-input-bar .emoji-btn:active {
  transform: scale(0.92);
}
.chat-input-bar .voice-msg-btn {
  background: rgba(236,72,153,0.08);
  border-color: rgba(236,72,153,0.15);
}
.chat-input-bar .voice-msg-btn:hover {
  background: rgba(236,72,153,0.18);
  border-color: rgba(236,72,153,0.35);
}
.chat-input-bar .voice-msg-btn.recording {
  background: rgba(239,68,68,0.2) !important;
  border-color: #ef4444 !important;
  animation: voicePulse 1s infinite;
}
.chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.chat-input {
  width: 100%;
  padding: 9px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 16px !important;
  color: var(--text);
  resize: none;
  max-height: 120px;
  min-height: 38px;
  line-height: 1.4;
  transition: border-color .2s, box-shadow .2s;
}
.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.12);
  outline: none;
}
.chat-input::placeholder { color: var(--muted); }
.send-btn {
  background: var(--gradient);
  border: none;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 50%;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .2s;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(139,92,246,.3);
}
.send-btn:active { transform: scale(.9); }
.send-btn:hover { box-shadow: 0 4px 16px rgba(139,92,246,.5); transform: translateY(-1px); }

.reply-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  border-top: 1px solid var(--border);
  font-size: .82rem;
  flex-shrink: 0;
}
.reply-preview.visible { display: flex; }
.reply-preview-text {
  flex: 1;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-preview .cancel-reply {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Emoji picker simple */
.emoji-picker-panel {
  display: none;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 12px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.emoji-picker-panel.visible { display: flex; }
.emoji-picker-panel button {
  background: none;
  border: none;
  font-size: 1.4rem;
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.emoji-picker-panel button:hover { background: var(--primary-dim); }

/* ---------- DM / Conversation ---------- */
.conv-list { display: flex; flex-direction: column; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
.conv-item:active { background: rgba(139,92,246,.08); }
.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-weight: 700;
  font-size: .92rem;
}
.conv-last {
  color: var(--muted);
  font-size: .82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conv-time {
  font-size: .7rem;
  color: var(--muted);
}

/* DM Bubbles */
.dm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior-y: contain;
}
.dm-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .92rem;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
  animation: msg-in .2s ease-out;
}
.dm-bubble.mine {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.dm-bubble.theirs {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.dm-bubble-time {
  font-size: .65rem;
  opacity: .6;
  margin-top: 4px;
}
.dm-bubble .read-receipt {
  font-size: .7rem;
  text-align: right;
  opacity: .6;
}
.dm-bubble .read-receipt.read { color: #60a5fa; opacity: 1; }
.dm-bubble .dm-image {
  max-width: 240px;
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.dm-bubble audio { display: none; }
.dm-bubble .audio-player {
  max-width: 260px;
  min-width: 180px;
}
.dm-bubble.mine .audio-player {
  background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(236,72,153,0.12));
  border-color: rgba(139,92,246,0.3);
}

/* ---------- Swipe Cards ---------- */
.swipe-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.card-stack {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3/4;
  perspective: 800px;
}
.swipe-card {
  position: absolute;
  inset: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: grab;
  transition: transform .4s cubic-bezier(.22,.68,0,1.2), opacity .3s;
  will-change: transform;
  touch-action: none;
  box-shadow: var(--shadow);
}
.swipe-card:active { cursor: grabbing; }
.swipe-card.behind {
  transform: scale(.92) translateY(12px);
  opacity: .7;
  pointer-events: none;
}
.swipe-card.swiping { transition: none; }
.swipe-card.swipe-left {
  transform: translateX(-150%) rotate(-25deg);
  opacity: 0;
  transition: transform .4s ease-in, opacity .3s;
}
.swipe-card.swipe-right {
  transform: translateX(150%) rotate(25deg);
  opacity: 0;
  transition: transform .4s ease-in, opacity .3s;
}
.swipe-card-photo {
  width: 100%;
  height: 65%;
  object-fit: cover;
  background: var(--border);
}
.swipe-card-info {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.swipe-card-name {
  font-size: 1.3rem;
  font-weight: 800;
}
.swipe-card-region {
  color: var(--muted);
  font-size: .85rem;
}
.swipe-card-bio {
  font-size: .88rem;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.swipe-card-rep {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .82rem;
  color: #fbbf24;
}
.swipe-overlay-label {
  position: absolute;
  top: 24px;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.swipe-overlay-label.like {
  right: 24px;
  border: 4px solid var(--success);
  color: var(--success);
  transform: rotate(15deg);
}
.swipe-overlay-label.pass {
  left: 24px;
  border: 4px solid var(--danger);
  color: var(--danger);
  transform: rotate(-15deg);
}

.swipe-actions {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 20px 0;
  flex-shrink: 0;
}
.swipe-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.swipe-btn:active { transform: scale(.9); }
.swipe-btn.pass:hover { border-color: var(--danger); box-shadow: 0 0 20px rgba(239,68,68,.3); }
.swipe-btn.like:hover { border-color: var(--success); box-shadow: 0 0 20px rgba(34,197,94,.3); }

.swipe-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px;
}
.swipe-empty .icon { font-size: 3rem; margin-bottom: 12px; }

/* Match Celebration */
.match-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,26,.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 7000;
  animation: match-pop .5s ease-out;
}
.match-overlay.visible { display: flex; }
@keyframes match-pop {
  0% { opacity: 0; transform: scale(.8); }
  60% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
.match-overlay .match-title {
  font-size: 2rem;
  font-weight: 900;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.match-overlay .match-avatars {
  display: flex;
  gap: -12px;
}
.match-overlay .match-avatars img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  object-fit: cover;
}

/* ---------- Friends ---------- */
.friend-section-title {
  padding: 12px 16px 8px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.friend-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
.friend-item:active { background: rgba(139,92,246,.08); }
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-weight: 700; font-size: .92rem; }
.friend-status { font-size: .78rem; color: var(--muted); }
.friend-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.friend-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.friend-action-btn:active { transform: scale(.9); }
.friend-action-icon { font-size: 1.1rem; line-height: 1; }
.friend-action-msg {
  border-color: rgba(139,92,246,0.3);
}
.friend-action-msg:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(139,92,246,0.2);
}
.friend-action-remove {
  border-color: rgba(239,68,68,0.2);
}
.friend-action-remove:hover {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.4);
}

/* ---------- Profile ---------- */
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 16px;
  text-align: center;
}
.profile-avatar-wrap {
  position: relative;
  margin-bottom: 16px;
}
.profile-avatar-wrap .avatar-xl {
  border: 3px solid var(--primary);
}
.profile-avatar-wrap .edit-avatar-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--card);
  color: #fff;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-nick {
  font-size: 1.3rem;
  font-weight: 800;
}
.profile-region {
  color: var(--muted);
  font-size: .88rem;
}
.profile-bio {
  color: var(--text);
  font-size: .9rem;
  margin-top: 8px;
  max-width: 320px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
}
.profile-stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
}
.profile-stat-value {
  font-size: 1.3rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.profile-stat-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
}

.profile-section {
  padding: 16px;
}
.profile-section h3 {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 16px 16px;
}
.profile-actions .btn {
  font-size: .82rem;
  padding: 8px 6px;
  min-height: 40px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reputation-stars {
  display: flex;
  gap: 2px;
  color: #fbbf24;
}
.reputation-stars .star-empty { color: var(--border); }

/* ---------- User Profile Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,26,.85);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 5000;
  animation: fade-in .2s;
}
.modal-overlay.visible { display: flex; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow-y: auto;
  animation: slide-up .3s ease-out;
  padding-bottom: var(--safe-bottom);
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 8px;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Voice Room Modal ---------- */
.voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,26,.95);
  display: none;
  flex-direction: column;
  z-index: 6000;
}
.voice-overlay.visible { display: flex; }
.voice-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.voice-header h3 {
  font-weight: 700;
  flex: 1;
}
.voice-participants {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 16px;
  padding: 24px 16px;
  overflow-y: auto;
  align-content: start;
}
.voice-participant {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.voice-participant .avatar,
.voice-participant .voice-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color .2s, box-shadow .2s;
  object-fit: cover;
  background: var(--card);
}
.voice-participant.speaking .avatar,
.voice-participant.speaking .voice-avatar {
  border-color: var(--success);
  box-shadow: 0 0 16px rgba(34,197,94,.4);
}
.voice-participant .voice-nick {
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}
.voice-controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.voice-controls .btn-icon {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
}
.voice-mute-btn {
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text);
}
.voice-mute-btn.muted {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.voice-leave-btn {
  background: var(--danger);
  border: none;
  color: #fff;
}

/* ---------- Leaderboard ---------- */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.leaderboard-rank {
  width: 28px;
  font-weight: 800;
  font-size: 1rem;
  text-align: center;
  color: var(--muted);
}
.leaderboard-rank.top-1 { color: #fbbf24; font-size: 1.2rem; }
.leaderboard-rank.top-2 { color: #94a3b8; font-size: 1.1rem; }
.leaderboard-rank.top-3 { color: #cd7f32; font-size: 1.05rem; }

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 400px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .3s ease-out;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-16px); }
}
.toast.removing { animation: toast-out .25s ease-in forwards; }

/* ---------- Empty States ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  gap: 12px;
}
.empty-state .icon { font-size: 3rem; }
.empty-state p { font-size: .92rem; }

/* ---------- Section subview toggle ---------- */
.subview { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.subview.active { display: flex; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* ---------- Media Queries ---------- */
@media (min-width: 768px) {
  #app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ============================================
   iOS Fixes
   ============================================ */

/* Prevent auto-zoom on all inputs (iOS zooms if font-size < 16px) */
input, textarea, select {
  font-size: 16px !important;
}

/* Fix iOS rubber-band scrolling */
.scrollable {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Fix iOS 100vh bug — use dvh where supported */
@supports (height: 100dvh) {
  html, body, #app { height: 100dvh; }
}

/* iOS standalone (PWA) — safe area handled by .view-header and .chat-header */

/* Fix iOS input styling */
input, textarea {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: var(--radius-sm);
}

/* Fix iOS touch delays */
* {
  touch-action: manipulation;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Banned avatar stamp */
.banned-avatar {
  filter: grayscale(1) brightness(0.5);
}
.banned-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-15deg);
  padding: 8px 24px;
  background: rgba(239, 68, 68, 0.15);
  border: 4px double #ef4444;
  border-radius: 8px;
  color: #ef4444;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
  pointer-events: none;
  white-space: nowrap;
  font-family: 'Arial Black', sans-serif;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
  animation: banStampIn .4s ease-out;
}
@keyframes banStampIn {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-30deg) scale(2); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-15deg) scale(1); }
}

/* Click feedback on messages */
.msg, .dm-bubble {
  transition: background .2s ease, transform .15s ease, box-shadow .2s ease;
  cursor: pointer;
  border-radius: 10px;
}
.msg:active {
  background: rgba(139,92,246,0.12);
  transform: scale(0.99);
}
.dm-bubble:active {
  transform: scale(0.97);
  filter: brightness(0.95);
}
/* Highlight when context menu is open */
.msg.msg-menu-active {
  background: linear-gradient(90deg, rgba(139,92,246,0.18), rgba(236,72,153,0.1));
  box-shadow: 0 0 20px rgba(139,92,246,0.2);
  transform: scale(1.005);
}
.dm-bubble.msg-menu-active {
  box-shadow: 0 0 24px rgba(139,92,246,0.35);
  transform: scale(1.01);
  filter: brightness(1.1);
}

/* Mention highlights */
.msg-mention-me {
  background: linear-gradient(90deg, rgba(236,72,153,0.12), rgba(139,92,246,0.05));
  border-left: 3px solid var(--secondary);
  border-radius: 0 10px 10px 0;
  padding-left: 8px !important;
  margin-left: -8px;
}
.msg-mention-flash {
  animation: mentionFlash 2s ease;
}
@keyframes mentionFlash {
  0%, 100% { background: linear-gradient(90deg, rgba(236,72,153,0.12), rgba(139,92,246,0.05)); }
  50% { background: linear-gradient(90deg, rgba(236,72,153,0.4), rgba(139,92,246,0.2)); box-shadow: 0 0 20px rgba(236,72,153,0.4); }
}

/* Game Hub cards */
.game-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: linear-gradient(145deg, rgba(26,26,46,0.9), rgba(20,20,40,0.95));
  border: 1px solid rgba(139,92,246,0.15);
  border-radius: 16px;
  cursor: pointer;
  transition: all .2s;
}
.game-card:hover {
  border-color: rgba(139,92,246,0.35);
  box-shadow: 0 0 20px rgba(139,92,246,0.1);
  transform: translateY(-2px);
}
.game-card:active { transform: scale(0.98); }
.game-card-soon {
  opacity: 0.5;
  pointer-events: none;
}
.game-card-icon {
  font-size: 2rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(236,72,153,0.15));
  border-radius: 14px;
  flex-shrink: 0;
}
.game-card-info { flex: 1; min-width: 0; }
.game-card-title {
  font-weight: 700;
  font-size: .95rem;
  margin-bottom: 4px;
}
.game-card-desc {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.4;
}
.game-card-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: rgba(139,92,246,0.15);
  color: var(--primary);
  border-radius: 100px;
}
.game-card-arrow {
  font-size: 1.5rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* Scenario game */
.scenario-section { width: 100%; max-width: 440px; }
.scenario-choice-btn {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: rgba(139,92,246,0.06);
  border: 1px solid rgba(139,92,246,0.15);
  border-radius: 11px;
  color: var(--text);
  font-size: .82rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: all .2s;
}
.scenario-choice-btn:hover {
  border-color: rgba(139,92,246,0.35);
  background: rgba(139,92,246,0.1);
}
.scenario-choice-btn.selected {
  border-color: var(--primary);
  background: rgba(139,92,246,0.15);
  box-shadow: 0 0 12px rgba(139,92,246,0.15);
}
.scenario-choice-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

/* Avatar upload button */
.avatar-upload {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  border: 2px solid rgba(139,92,246,0.3);
  transition: border-color .2s, box-shadow .2s;
  background: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(236,72,153,0.1));
}
.avatar-upload:hover, .avatar-upload:active {
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(139,92,246,0.25);
}
.avatar-upload-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,26,0.5);
  font-size: 1.5rem;
  transition: opacity .2s;
}
.avatar-upload:hover .avatar-upload-overlay {
  background: rgba(10,10,26,0.3);
}
.avatar-upload-img[src]:not([src=""]) ~ .avatar-upload-overlay {
  opacity: 0;
}
.avatar-upload:hover .avatar-upload-img[src]:not([src=""]) ~ .avatar-upload-overlay {
  opacity: 1;
}
.avatar-upload-hint {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 6px;
}

/* Gender picker */
.gender-btn {
  flex: 1;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: .82rem;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.gender-btn:hover {
  border-color: rgba(139,92,246,0.3);
}
.gender-btn.selected {
  border-color: var(--primary);
  background: var(--primary-dim);
  box-shadow: 0 0 12px rgba(139,92,246,0.2);
}

/* Status toggle */
.status-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.status-toggle-label {
  font-size: .9rem;
  font-weight: 600;
}
.status-toggle-hint {
  font-size: .75rem;
  color: var(--muted);
}
.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background .25s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .25s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
  box-shadow: 0 0 10px rgba(139,92,246,0.3);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* Fix iOS select dropdown */
select {
  -webkit-appearance: none;
  background-color: var(--bg);
}

/* Smooth scrolling on iOS */
.messages-area, .room-list, .friends-list, .conv-list {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Fix position:fixed with iOS keyboard */
.view.active {
  position: relative;
}

/* ---------- Voice Join Button ---------- */
.voice-join-btn {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  animation: voicePulse 2s ease-in-out infinite;
  white-space: nowrap;
}
.voice-join-btn.active {
  background: #ef4444;
  animation: none;
}
@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(139, 92, 246, 0); }
}

/* ---------- Room Star Button ---------- */
.room-star-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

/* ── Rank System ── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #8b5cf6;
  margin-right: 4px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* Level-up system message */
.msg-system-levelup {
  padding: 8px 0 !important;
}
.msg-system-levelup .levelup-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: rgba(139, 92, 246, 0.08);
  border-left: 3px solid #8b5cf6;
  border-radius: 8px;
  margin: 0 12px;
}
.levelup-img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid #8b5cf6;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(139, 92, 246, 0.15);
}
.levelup-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.levelup-text {
  flex: 1;
  min-width: 0;
}
.levelup-title {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 2px;
}
.levelup-rank {
  font-size: 15px;
  font-weight: 700;
  color: #8b5cf6;
}

@media (max-width: 600px) {
  .levelup-card { padding: 10px 12px; gap: 10px; }
  .levelup-img { width: 42px; height: 42px; }
  .levelup-title { font-size: 12px; }
  .levelup-rank { font-size: 13px; }
}

/* ══════════════════════════════════════════════
   Level Up Full-Screen Animation
   ══════════════════════════════════════════════ */
.lu-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: background 0.6s ease;
}
.lu-overlay.lu-active {
  background: rgba(0, 0, 0, 0.85);
  pointer-events: auto;
}
.lu-overlay.lu-exit {
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
}
.lu-overlay.lu-exit .lu-inner { opacity: 0; transform: scale(1.2); }

.lu-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.6s ease 0.2s, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s;
}
.lu-active .lu-inner { opacity: 1; transform: scale(1); }

/* Light burst */
.lu-burst {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  animation: none;
}
.lu-active .lu-burst {
  animation: luBurst 1.5s ease-out 0.3s forwards;
}
@keyframes luBurst {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0.8; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* Ring */
.lu-ring {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 2px solid #8b5cf6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%) scale(0);
  opacity: 0;
}
.lu-active .lu-ring {
  animation: luRing 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s forwards;
}
@keyframes luRing {
  0% { transform: translate(-50%, -60%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -60%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -60%) scale(1.15); opacity: 0.6; }
}

/* Character image */
.lu-img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid #8b5cf6;
  overflow: hidden;
  background: rgba(255,255,255,0.1);
  transform: scale(0) rotate(-20deg);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
}
.lu-active .lu-img {
  animation: luImg 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s forwards;
}
@keyframes luImg {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.lu-img img { width: 100%; height: 100%; object-fit: cover; }

/* Level label */
.lu-level-label {
  font-size: 12px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: #94a3b8;
  margin-top: 16px;
  opacity: 0;
  transform: translateY(10px);
}
.lu-active .lu-level-label {
  animation: luFadeUp 0.5s ease 0.9s forwards;
}

/* Level number */
.lu-level-num {
  font-size: 64px;
  font-weight: 900;
  color: #8b5cf6;
  line-height: 1;
  opacity: 0;
  transform: scale(0.5);
  text-shadow: 0 0 40px currentColor;
}
.lu-active .lu-level-num {
  animation: luScale 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1s forwards;
}

/* Rank name */
.lu-rank-name {
  font-size: 28px;
  font-weight: 800;
  color: #8b5cf6;
  text-shadow: 0 0 30px currentColor;
  opacity: 0;
  transform: translateY(10px);
  letter-spacing: 0.02em;
}
.lu-active .lu-rank-name {
  animation: luFadeUp 0.5s ease 1.2s forwards;
}

/* Universe */
.lu-universe {
  font-size: 14px;
  color: #64748b;
  opacity: 0;
  transform: translateY(10px);
  letter-spacing: 0.1em;
}
.lu-active .lu-universe {
  animation: luFadeUp 0.5s ease 1.4s forwards;
}

/* Hint */
.lu-hint {
  font-size: 11px;
  color: #475569;
  margin-top: 24px;
  opacity: 0;
  letter-spacing: 0.05em;
}
.lu-active .lu-hint {
  animation: luFadeUp 0.5s ease 2s forwards;
}

/* Particles */
.lu-particles {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  width: 0;
  height: 0;
  z-index: 1;
}
.lu-particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
}
.lu-active .lu-particle {
  animation: luParticle 1.2s ease-out forwards;
}
@keyframes luParticle {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* Shared keyframes */
@keyframes luFadeUp {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes luScale {
  0% { opacity: 0; transform: scale(0.5); }
  100% { opacity: 1; transform: scale(1); }
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .lu-img { width: 90px; height: 90px; }
  .lu-ring { width: 130px; height: 130px; }
  .lu-level-num { font-size: 48px; }
  .lu-rank-name { font-size: 22px; }
  .lu-burst { width: 350px; height: 350px; }
}

/* ══════════════════════════════════════════════
   PWA Install Prompt (mobile only)
   ══════════════════════════════════════════════ */
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  animation: pwaInstallPulse 3s ease-in-out infinite;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.4);
}
.pwa-install-btn:active { transform: scale(0.95); }
@keyframes pwaInstallPulse {
  0%, 100% { box-shadow: 0 2px 12px rgba(139, 92, 246, 0.4); }
  50% { box-shadow: 0 2px 20px rgba(139, 92, 246, 0.7); }
}

/* iOS Tutorial Modal */
.ios-install-overlay {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  transition: background 0.3s ease;
}
.ios-install-overlay.active {
  background: rgba(0, 0, 0, 0.6);
  pointer-events: auto;
}
.ios-install-modal {
  width: 100%;
  max-width: 420px;
  background: #1e1e2e;
  border-radius: 20px 20px 0 0;
  padding: 28px 24px 36px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}
.ios-install-overlay.active .ios-install-modal {
  transform: translateY(0);
}
.ios-install-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ios-install-title {
  font-size: 22px;
  font-weight: 800;
  color: #f1f5f9;
  margin-bottom: 6px;
}
.ios-install-subtitle {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 24px;
}
.ios-install-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
.ios-install-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.ios-install-step-num {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(139, 92, 246, 0.15);
  border-radius: 12px;
}
.ios-install-step-text {
  flex: 1;
  font-size: 14px;
  color: #cbd5e1;
  line-height: 1.5;
  padding-top: 8px;
}
.ios-install-step-text strong {
  color: #f1f5f9;
  font-weight: 700;
}
.ios-install-gotit {
  width: 100%;
  padding: 14px;
  background: #8b5cf6;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
.ios-install-gotit:active { opacity: 0.85; }
