:root {
  --bg: #0b0b14;
  --bg2: #12121f;
  --card: rgba(255,255,255,0.06);
  --card-border: rgba(255,255,255,0.1);
  --primary: #00d4aa;
  --primary-dark: #00a88a;
  --secondary: #4f8cff;
  --danger: #ff4d6d;
  --text: #f0f0f5;
  --text-muted: #9a9ab0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  --top-h: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
}

body.rtl { direction: rtl; }
body.ltr { direction: ltr; }

.hidden { display: none !important; }
.active { display: block; }

/* Loading */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.loader { text-align: center; }
.mafia-logo {
  font-size: 64px;
  animation: pulse 1.5s ease-in-out infinite;
}
.loader-bar {
  width: 180px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  margin: 20px auto 12px;
  overflow: hidden;
}
.loader-fill {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 4px;
  animation: loading 1.2s ease-in-out infinite;
}

/* App Layout */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.top-bar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.profile-btn {
  position: relative;
  width: 40px;
  height: 40px;
  cursor: pointer;
}
.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  background: #333;
}
.rank-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--primary);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.top-title {
  flex: 1;
  text-align: center;
}
.top-title h1 {
  font-size: 16px;
  font-weight: 700;
}
.online-count {
  font-size: 11px;
  color: var(--primary);
}
.top-actions {
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--card);
  border-radius: 50%;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg2);
  border-top: 1px solid var(--card-border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 20px; }

/* Main Content */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: 20px;
}
.tab-screen { display: none; }
.tab-screen.active { display: block; }

/* Glass Card */
.glass {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Hero */
.hero-card {
  padding: 24px 20px;
  text-align: center;
  margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(0,212,170,0.15), rgba(79,140,255,0.1));
}
.hero-card h2 { font-size: 20px; margin-bottom: 8px; }
.hero-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.hero-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #000;
}
.btn-secondary {
  background: linear-gradient(135deg, var(--secondary), #3a6fd9);
  color: #fff;
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-lg { padding: 14px 24px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #000;
  border: none;
  font-size: 16px;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  padding: 14px 8px;
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-header h2 { font-size: 18px; }

/* Lists */
.list-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}
.card-item:active { background: rgba(255,255,255,0.1); }
.card-item .avatar-sm {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #333;
}
.card-item .info { flex: 1; min-width: 0; }
.card-item .info h4 {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-item .info p {
  font-size: 12px;
  color: var(--text-muted);
}
.card-item .badge {
  background: var(--primary);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
}

/* Search */
.search-bar {
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-bar input:focus {
  border-color: var(--primary);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 500;
  padding: 0;
}
.modal-content {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  border-radius: 20px 20px 0 0;
  position: relative;
  animation: slideUp 0.3s ease;
}
.modal-content.scrollable { max-height: 80vh; }
.modal-close {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--card);
  border-radius: 50%;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
body.ltr .modal-close { left: auto; right: 12px; }

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}
.switch-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.switch {
  position: relative;
  width: 48px;
  height: 28px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #333;
  border-radius: 28px;
  cursor: pointer;
  transition: 0.3s;
}
.slider:before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.radio-group {
  display: flex;
  gap: 16px;
}
.radio-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
}

/* Profile Modal */
.profile-header {
  text-align: center;
  padding-top: 10px;
}
.avatar-lg {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  object-fit: cover;
  background: #333;
}
.profile-header h2 { margin-top: 10px; font-size: 20px; }
.profile-header p { color: var(--text-muted); font-size: 13px; }
.rank-display {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
}
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
  text-align: center;
}
.profile-stats strong {
  display: block;
  font-size: 20px;
  color: var(--primary);
}
.profile-stats span {
  font-size: 11px;
  color: var(--text-muted);
}

/* Menu */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: start;
}

/* Sub tabs */
.tabs-sub {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.sub-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: var(--card);
  color: var(--text-muted);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.sub-tab.active {
  background: var(--primary);
  color: #000;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,20,30,0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 1000;
  border: 1px solid var(--card-border);
  max-width: 90%;
  text-align: center;
  animation: fadeIn 0.25s ease;
}

/* Screen full */
.screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }

/* Performance */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Premium atmospheric layer: restrained neon bloom and tactile glass surfaces. */
body {
  background:
    radial-gradient(ellipse at 12% 8%, rgba(0, 212, 170, 0.10), transparent 34%),
    radial-gradient(ellipse at 88% 24%, rgba(79, 140, 255, 0.13), transparent 38%),
    radial-gradient(ellipse at 50% 100%, rgba(147, 82, 255, 0.08), transparent 42%),
    var(--bg);
}
.top-bar {
  background: rgba(12, 12, 25, 0.82);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.glass {
  background: linear-gradient(145deg, rgba(255,255,255,0.075), rgba(255,255,255,0.025));
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 14px 42px rgba(0,0,0,0.24), inset 0 1px 0 rgba(255,255,255,0.055);
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}
.hero-card {
  position: relative;
  overflow: hidden;
  border-color: rgba(0,212,170,0.24);
  background: linear-gradient(135deg, rgba(0,212,170,0.15), rgba(79,140,255,0.12) 55%, rgba(143,84,255,0.08));
}
.hero-card::before {
  content: '';
  position: absolute;
  width: 170px;
  height: 170px;
  top: -105px;
  left: -45px;
  border-radius: 50%;
  background: rgba(0,212,170,0.22);
  filter: blur(38px);
  pointer-events: none;
}
.btn {
  box-shadow: 0 5px 16px rgba(0,0,0,0.18);
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 8px 22px rgba(0,0,0,0.24); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
