:root {
  --brand: #6a1b9a;
  --brand2: #8e24aa;
  --pink: #ff4081;
  --like: #00c853;
  --pass: #ff5252;
  --bg: var(--tg-theme-bg-color, #f4f4f7);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --muted: var(--tg-theme-hint-color, #8a8a90);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, "SF Pro", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior: none;
}
#app { min-height: 100vh; padding-bottom: var(--tabbar-h); }
.hidden { display: none !important; }

/* ---------- Loading ---------- */
.screen-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 24px;
}
.logo {
  font-size: 42px; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--brand), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #ddd; border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottom bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--tabbar-h);
  display: flex; background: var(--card);
  border-top: 1px solid rgba(0,0,0,0.07);
  z-index: 100;
}
#tabbar .tab {
  flex: 1; border: none; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; cursor: pointer; position: relative;
}
#tabbar .tab .ico { font-size: 22px; }
#tabbar .tab.active { color: var(--brand); font-weight: 700; }
.badge {
  position: absolute; top: 8px; right: 28%;
  background: var(--pink); color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---------- Header ---------- */
.page { padding: 16px; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.page-header h1 {
  margin: 0; font-size: 26px; font-weight: 800;
  background: linear-gradient(135deg, var(--brand), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.icon-btn {
  border: none; background: var(--card); width: 40px; height: 40px;
  border-radius: 50%; font-size: 18px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ---------- Swipe card ---------- */
#deck {
  position: relative; height: calc(100vh - var(--tabbar-h) - 150px);
  margin: 8px 16px;
}
.card {
  position: absolute; inset: 0;
  border-radius: 20px; overflow: hidden;
  background: #222 center/cover no-repeat;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  will-change: transform;
  user-select: none;
}
.card .photo-strip {
  position: absolute; top: 8px; left: 12px; right: 12px;
  display: flex; gap: 4px; z-index: 3;
}
.card .photo-strip i {
  flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.4);
}
.card .photo-strip i.on { background: #fff; }
.card .tap-zones { position: absolute; inset: 0; display: flex; z-index: 2; }
.card .tap-zones div { flex: 1; }
.card .overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 24px 18px 18px; z-index: 3;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  color: #fff;
}
.card .overlay h2 { margin: 0; font-size: 24px; }
.card .overlay h2 span { font-weight: 400; opacity: 0.9; }
.card .overlay .meta { font-size: 14px; opacity: 0.9; margin-top: 4px; }
.card .overlay .bio { font-size: 13px; opacity: 0.85; margin-top: 6px; line-height: 1.5; }
.card .stamp {
  position: absolute; top: 40px; font-size: 34px; font-weight: 900;
  padding: 4px 16px; border: 4px solid; border-radius: 12px;
  text-transform: uppercase; opacity: 0; z-index: 4;
}
.card .stamp.like { left: 20px; color: var(--like); border-color: var(--like); transform: rotate(-18deg); }
.card .stamp.nope { right: 20px; color: var(--pass); border-color: var(--pass); transform: rotate(18deg); }

/* ---------- Action buttons ---------- */
.actions {
  position: fixed; bottom: calc(var(--tabbar-h) + 14px); left: 0; right: 0;
  display: flex; gap: 18px; align-items: center; justify-content: center; z-index: 50;
}
.action {
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18); background: #fff;
}
.action.big { width: 64px; height: 64px; font-size: 28px; }
.action.sm { width: 50px; height: 50px; font-size: 22px; }
.action.pass { color: var(--pass); }
.action.like { color: var(--like); }
.action.super { color: #2196f3; }
.action:active { transform: scale(0.9); }

/* ---------- Empty state ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 60vh; text-align: center; color: var(--muted); gap: 12px; padding: 0 30px;
}
.empty .big { font-size: 56px; }

/* ---------- Chat list ---------- */
.match-list { padding: 0 12px; }
.match-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 14px; cursor: pointer;
}
.match-row:active { background: var(--card); }
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: #ccc center/cover no-repeat; flex-shrink: 0;
  border: 2px solid var(--brand2);
}
.match-row .info { flex: 1; min-width: 0; }
.match-row .info .nm { font-weight: 700; font-size: 15px; }
.match-row .info .last {
  color: var(--muted); font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.match-row .unread {
  background: var(--pink); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.new-matches { display: flex; gap: 12px; overflow-x: auto; padding: 8px 14px 16px; }
.new-matches .nm-item { text-align: center; flex-shrink: 0; }
.new-matches .nm-item .avatar { width: 64px; height: 64px; }
.new-matches .nm-item span { font-size: 12px; display: block; margin-top: 4px; }

/* ---------- Chat page ---------- */
#chatPage { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; flex-direction: column; }
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.chat-header .avatar { width: 40px; height: 40px; }
.chat-header .nm { font-weight: 700; }
.chat-header .back { border: none; background: none; font-size: 24px; cursor: pointer; color: var(--brand); }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 75%; padding: 9px 14px; border-radius: 18px; font-size: 14px; line-height: 1.5;
  word-break: break-word;
}
.bubble.me { align-self: flex-start; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-end; background: var(--card); border-bottom-left-radius: 4px; }
.bubble .t { font-size: 10px; opacity: 0.6; margin-top: 3px; }
.typing { align-self: flex-end; color: var(--muted); font-size: 13px; padding: 4px 10px; }
.chat-input {
  display: flex; gap: 8px; padding: 10px; background: var(--card);
}
.chat-input input {
  flex: 1; border: none; border-radius: 22px; padding: 11px 16px;
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}
.chat-input button {
  border: none; background: var(--brand); color: #fff; width: 44px; height: 44px;
  border-radius: 50%; font-size: 18px; cursor: pointer;
}

/* ---------- Profile / form ---------- */
.profile-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.profile-photos .ph {
  aspect-ratio: 3/4; border-radius: 12px; background: #ddd center/cover no-repeat;
  position: relative; overflow: hidden;
}
.profile-photos .ph .del {
  position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,0.6); color: #fff;
  border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 14px;
}
.profile-photos .add {
  aspect-ratio: 3/4; border-radius: 12px; border: 2px dashed var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  color: var(--muted); cursor: pointer; background: var(--card);
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid rgba(0,0,0,0.1); border-radius: 12px;
  padding: 12px; font-size: 15px; background: var(--card); color: var(--text);
  font-family: inherit; outline: none;
}
.field textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.range-val { font-weight: 700; color: var(--brand); }
.btn-primary {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  background: linear-gradient(135deg, var(--brand), var(--pink)); color: #fff;
  font-size: 16px; font-weight: 700; cursor: pointer; margin-top: 8px;
}
.btn-primary:active { opacity: 0.85; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; border: 1px solid rgba(0,0,0,0.12); background: var(--card); color: var(--text);
  padding: 11px; border-radius: 12px; cursor: pointer; font-size: 14px;
}
.seg button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Match modal ---------- */
#matchModal {
  position: fixed; inset: 0; z-index: 300;
  background: linear-gradient(160deg, var(--brand), var(--pink));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; gap: 18px; padding: 30px;
}
#matchModal h1 { font-size: 40px; margin: 0; }
#matchModal .avatars { display: flex; }
#matchModal .avatars .avatar { width: 110px; height: 110px; border: 4px solid #fff; }
#matchModal .avatars .avatar:nth-child(2) { margin-right: -24px; }
#matchModal button { width: 80%; }
#matchModal .ghost {
  background: transparent; border: 2px solid #fff; color: #fff;
  border-radius: 14px; padding: 13px; cursor: pointer; font-size: 15px; width: 80%;
}

/* ---------- Filter sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 250; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end;
}
.sheet .panel {
  background: var(--bg); width: 100%; border-radius: 20px 20px 0 0; padding: 20px;
  max-height: 80vh; overflow-y: auto;
}
.sheet h3 { margin: 0 0 16px; }
