:root {
  --accent: #6C63FF;
  --accent-soft: #EEEBFF;
  --bg: #F0F2F5;
  --surface: #FFFFFF;
  --surface-2: #FAFBFC;
  --border: #DDE1E7;
  --text: #1A1D23;
  --muted: #6B7280;
  --male: #3B82F6;
  --female: #EC4899;
  --heart: #F43F5E;
  --heart-bg: #FFF1F3;
  --discard: #64748B;
  --discard-bg: #F1F5F9;
  --shadow: 0 2px 8px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1116;
    --surface: #1A1D23;
    --surface-2: #22252C;
    --border: #2A2D35;
    --text: #E5E7EB;
    --muted: #9CA3AF;
    --accent-soft: #2A2558;
    --heart-bg: #2A1520;
    --discard-bg: #1A1D25;
    --shadow: 0 2px 10px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overscroll-behavior: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button, input { font: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

/* `hidden` attribute must beat explicit display: flex/grid declarations */
[hidden] { display: none !important; }

/* ─── Top bar ─── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 0;
}
.title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.title-row h1 { margin: 0; font-size: 17px; font-weight: 700; }
.counts { color: var(--muted); font-size: 12px; }

.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.search-field {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 10px; height: 40px;
  transition: border-color .1s, box-shadow .1s;
}
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-field .icon { font-size: 13px; color: var(--muted); }
.search-field input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  font-size: 16px;    /* iOS: 16px prevents zoom-on-focus */
  min-width: 0;
}
.search-field .clear {
  color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px;
  min-width: 28px; min-height: 28px;
}
.filters-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border); font-size: 18px;
}
.filters-btn:active { background: var(--accent-soft); }

.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; padding: 10px 6px; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 500;
  min-height: 40px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .badge {
  font-size: 11px; padding: 1px 6px; border-radius: 8px;
  background: var(--bg); color: var(--muted); margin-left: 2px;
}
.tab.active .badge { background: var(--accent-soft); color: var(--accent); }

/* ─── List ─── */
.list-container {
  flex: 1; padding: 8px 10px 20px; position: relative;
}
.list { list-style: none; margin: 0; padding: 0; }
.card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
  margin-bottom: 8px; box-shadow: var(--shadow);
}
.card .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.card .dot.male { background: var(--male); }
.card .dot.female { background: var(--female); }
.card .dot.nb { background: #D1D5DB; }
.card .main { flex: 1; min-width: 0; }
.card .name { font-size: 16px; font-weight: 600; margin-bottom: 2px;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { font-size: 12px; color: var(--muted);
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta .gender.male { color: var(--male); }
.card .meta .gender.female { color: var(--female); }
.card .meta .sep { margin: 0 5px; opacity: .5; }
.card .meta .score { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--text); }
.card .actions { display: flex; gap: 2px; flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--muted);
  transition: background-color .1s, color .1s;
}
.icon-btn.fav:hover,     .icon-btn.fav:active     { background: var(--heart-bg);   color: var(--heart); }
.icon-btn.disc:hover,    .icon-btn.disc:active    { background: var(--discard-bg); color: var(--discard); }
.icon-btn.restore:hover, .icon-btn.restore:active { background: var(--accent-soft); color: var(--accent); }

.status {
  text-align: center; padding: 40px 20px; color: var(--muted); font-size: 14px;
}
.status.error { color: var(--heart); }

/* ─── Drawer ─── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 20; animation: fadeIn .15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--surface); border-radius: 16px 16px 0 0;
  max-height: 90dvh; display: flex; flex-direction: column;
  animation: slideUp .2s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0; font-size: 16px; }
.close-btn { font-size: 24px; line-height: 1; width: 40px; height: 40px; }

.drawer-content {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}
.drawer-content section { margin-bottom: 18px; }
.drawer-content label {
  display: block; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted); margin-bottom: 8px;
}
.drawer-content .muted { font-weight: 400; text-transform: none; letter-spacing: 0; }
.drawer-content .hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

.seg-control {
  display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px;
}
.seg-control button {
  flex: 1; padding: 8px; font-size: 13px; border-radius: 8px;
  color: var(--muted); font-weight: 500; min-height: 36px;
}
.seg-control button.active {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

#countrySearch {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
  margin-bottom: 6px;
}
.inline-actions { display: flex; gap: 14px; margin-bottom: 6px; }
.link-btn { color: var(--accent); font-size: 12px; padding: 4px 0; min-height: 28px; }
.country-list {
  max-height: 180px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg);
}
.country-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); font-size: 13px; min-height: 36px;
}
.country-row:last-child { border-bottom: none; }
.country-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.country-row label { margin: 0; text-transform: none; letter-spacing: 0; color: var(--text); flex: 1; font-weight: 400; font-size: 13px; }

.range-pair { display: flex; gap: 10px; align-items: center; }
.range-pair input { flex: 1; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

.drawer-footer {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--border); background: var(--surface);
}
.btn-primary {
  flex: 2; background: var(--accent); color: white; font-weight: 600;
  padding: 12px; border-radius: 10px; font-size: 15px; min-height: 44px;
}
.btn-ghost {
  flex: 1; background: var(--bg); color: var(--text);
  padding: 12px; border-radius: 10px; font-size: 15px; min-height: 44px;
}
.btn-primary:active { background: #5a52e6; }

/* ─── Tablet / desktop widen ─── */
@media (min-width: 700px) {
  body { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .drawer { left: 50%; right: auto; transform: translateX(-50%); width: 100%; max-width: 720px; }
  .drawer { animation: slideUp .2s ease-out; }
  @keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
}
