:root {
  --primary: #1A73A7;
  --primary-dark: #155F8A;
  --gradient: linear-gradient(135deg, #1A73A7, #D4A843);
  --bg: #F5F5F8;
  --card-bg: #FFFFFF;
  --text: #21262E;
  --text-light: #8E8E93;
  --success: #4CD964;
  --danger: #FF3B30;
  --gold: #D4A843;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
  --radius: 16px;
}

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

/* ── Darfash Icon ─────────────────────────── */
.darfash-icon { height: 42px; vertical-align: middle; margin-right: 4px; }
.darfash-icon-sm { height: 26px; vertical-align: middle; margin-right: 2px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ── App Shell ────────────────────────────── */
.app {
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  position: absolute;
  inset: 0;
  z-index: 1;
}
.screen.active { display: flex; z-index: 2; }

/* ── Header ───────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--card-bg);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.header .logo {
  font-size: 28px;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}
.header-actions { display: flex; gap: 8px; }
.header-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: var(--bg);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
}
.header-btn:hover { transform: scale(1.1); }

/* ── Auth Screen ──────────────────────────── */
.auth-screen {
  justify-content: center;
  align-items: center;
  padding: 40px 30px;
  background: linear-gradient(180deg, #0D3B66 0%, #1A73A7 50%, #D4A843 100%);
}
.auth-logo {
  font-size: 42px;
  font-weight: 900;
  color: white;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.auth-tagline {
  color: rgba(255,255,255,0.9);
  font-size: 16px;
  margin-bottom: 48px;
}
.auth-card {
  background: white;
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--bg);
}
.auth-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-light);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.3s;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
  display: block;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #E8E8ED;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
}
.btn-primary {
  background: var(--gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(26,115,167,0.4);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(26,115,167,0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-outline {
  background: none;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.error-msg {
  background: #FFF0F0;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.show { display: block; }

/* ── Profile Setup ────────────────────────── */
.setup-screen {
  padding: 24px;
  overflow-y: auto;
}
.setup-screen h2 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 4px;
}
.setup-screen p {
  color: var(--text-light);
  margin-bottom: 24px;
}
.avatar-upload {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: var(--bg);
  margin: 0 auto 24px;
  display: flex;
  align-items: center; justify-content: center;
  font-size: 40px;
  color: var(--text-light);
  cursor: pointer;
  border: 3px dashed #D1D1D6;
  transition: border-color 0.3s;
  overflow: hidden;
}
.avatar-upload:hover { border-color: var(--primary); }
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; }

/* ── Photo Grid (Setup) ──────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 8px;
}
.photo-slot {
  aspect-ratio: 3/4;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.photo-slot.add-photo {
  border: 2px dashed #D1D1D6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.3s, background 0.3s;
}
.photo-slot.add-photo:hover { border-color: var(--primary); background: rgba(255,68,88,0.04); }
.photo-slot .plus { font-size: 28px; color: var(--primary); font-weight: 300; }
.photo-slot .photo-label { font-size: 11px; color: var(--text-light); }
.photo-slot.filled img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .photo-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.6); color: white;
  border: none; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.photo-count { font-size: 12px; color: var(--text-light); }
.photo-count.valid { color: var(--success); }
.photo-count.invalid { color: var(--danger); }

/* ── Photo Carousel (Cards) ──────────────── */
.card-photo { position: relative; }
.card-photo .photo-dots {
  position: absolute; top: 8px; left: 8px; right: 8px;
  display: flex; gap: 4px; z-index: 5;
}
.card-photo .photo-dot {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(255,255,255,0.4);
  transition: background 0.3s;
}
.card-photo .photo-dot.active { background: rgba(255,255,255,0.95); }
.card-photo .photo-nav {
  position: absolute; top: 0; bottom: 30%; z-index: 4;
  width: 50%; cursor: pointer;
}
.card-photo .photo-nav.prev { left: 0; }
.card-photo .photo-nav.next { right: 0; }

/* ── Profile Photos ──────────────────────── */
.profile-photos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
}
.profile-photos-grid .photo-thumb {
  aspect-ratio: 3/4;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
.profile-photos-grid .photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.profile-photos-grid .photo-thumb .photo-remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.6); color: white;
  border: none; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.profile-add-photo {
  aspect-ratio: 3/4;
  border: 2px dashed #D1D1D6;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--text-light);
  cursor: pointer; transition: border-color 0.3s;
}
.profile-add-photo:hover { border-color: var(--primary); }

/* ── Swipe Cards ──────────────────────────── */
.cards-container {
  flex: 1;
  position: relative;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-stack {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3/4;
}
.card {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: var(--card-bg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  cursor: grab;
  will-change: transform;
  transition: transform 0.1s ease-out;
}
.card:active { cursor: grabbing; }
.card-photo {
  width: 100%;
  height: 70%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-photo .initial {
  font-size: 80px;
  font-weight: 800;
  color: rgba(255,255,255,0.8);
}
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-gradient {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 50%;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}
.card-info {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  padding: 20px;
  color: white;
}
.card-info h3 {
  font-size: 26px;
  font-weight: 700;
}
.card-info h3 span {
  font-weight: 400;
  font-size: 22px;
  opacity: 0.9;
}
.card-info .city {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 2px;
}
.card-info .bio {
  font-size: 14px;
  margin-top: 8px;
  opacity: 0.9;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-stamp {
  position: absolute;
  top: 40px;
  padding: 8px 20px;
  border: 4px solid;
  border-radius: 10px;
  font-size: 36px;
  font-weight: 900;
  transform: rotate(-20deg);
  opacity: 0;
  transition: opacity 0.1s;
  pointer-events: none;
}
.card-stamp.like {
  left: 20px;
  color: var(--success);
  border-color: var(--success);
}
.card-stamp.nope {
  right: 20px;
  color: var(--danger);
  border-color: var(--danger);
  transform: rotate(20deg);
}
.no-more-cards {
  text-align: center;
  color: var(--text-light);
}
.no-more-cards .emoji { font-size: 60px; margin-bottom: 16px; }
.no-more-cards h3 { font-size: 22px; color: var(--text); margin-bottom: 8px; }

/* ── Swipe Buttons ────────────────────────── */
.swipe-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 16px 20px 28px;
}
.swipe-btn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center; justify-content: center;
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  background: white;
}
.swipe-btn:hover { transform: scale(1.1); }
.swipe-btn:active { transform: scale(0.95); }
.swipe-btn.nope { color: var(--danger); }
.swipe-btn.like { color: var(--success); font-size: 32px; }

/* ── Matches ──────────────────────────────── */
.matches-screen {
  padding: 0;
  overflow-y: auto;
}
.matches-header {
  padding: 20px;
  font-size: 28px;
  font-weight: 800;
}
.matches-header span {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.match-list { padding: 0 20px 100px; }
.match-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--card-bg);
  border-radius: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s;
}
.match-item:hover { transform: translateX(4px); }
.match-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center; justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 20px;
  flex-shrink: 0;
}
.match-info h4 { font-size: 16px; font-weight: 600; }
.match-info p { font-size: 13px; color: var(--text-light); margin-top: 2px; }
.no-matches {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.no-matches .emoji { font-size: 50px; margin-bottom: 12px; }

/* ── Profile View ─────────────────────────── */
.profile-screen {
  padding: 24px;
  overflow-y: auto;
}
.profile-card {
  background: var(--card-bg);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.profile-photo {
  width: 100%; height: 200px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center; justify-content: center;
  font-size: 64px;
  color: rgba(255,255,255,0.8);
  font-weight: 800;
}
.profile-details {
  padding: 20px;
}
.profile-details h2 {
  font-size: 24px;
  font-weight: 700;
}
.profile-details .meta {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 4px;
}
.profile-details .bio-text {
  margin-top: 12px;
  line-height: 1.5;
  color: #444;
}
.btn-logout {
  background: none;
  border: 2px solid var(--danger);
  color: var(--danger);
  padding: 14px;
  width: 100%;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
}
.btn-logout:hover { background: #FFF0F0; }

/* ── Bottom Nav ───────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid rgba(0,0,0,0.05);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  position: relative;
  z-index: 10;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  font-size: 11px;
  color: var(--text-light);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-item .icon { font-size: 24px; }
.nav-item.active { color: var(--primary); }

/* ── Match Popup ──────────────────────────── */
.match-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.match-popup.show { display: flex; }
.match-popup-content {
  text-align: center;
  padding: 40px;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.match-popup-content h2 {
  font-size: 42px;
  font-weight: 900;
  background: linear-gradient(135deg, #D4A843, #1A73A7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}
.match-popup-content p {
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  margin-bottom: 30px;
}
.match-popup .btn {
  max-width: 240px;
  margin: 0 auto;
}

/* ── Loading ──────────────────────────────── */
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--bg);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ───────────────────────────── */
@media (min-width: 431px) {
  .app {
    border-left: 1px solid rgba(0,0,0,0.08);
    border-right: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 0 60px rgba(0,0,0,0.08);
  }
}
