:root{
  --base:#0000FF;
  --fc:#8A63D2;

  --bg:#F6F7FB;
  --panel:#FFFFFF;
  --text:#0B0D12;
  --muted:#626A7D;
  --border:#E7E9F2;
  --chipBg: rgba(0,0,0,.04);
  --shadow: 0 10px 30px rgba(10, 12, 20, .08);

  --r14:14px;
  --r18:18px;
  --r22:22px;

  --sans:-apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
         "Segoe UI", Roboto, Helvetica, Arial, system-ui;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
[data-theme="dark"]{
  --bg:#070812;
  --panel:#0C0E1A;
  --text:#F2F3FF;
  --muted:#A7AACC;
  --border:rgba(255,255,255,.10);
  --chipBg: rgba(255,255,255,.08);
  --shadow: 0 14px 40px rgba(0,0,0,.55);
}

*{ box-sizing:border-box; }
html, body{
  width:100%;
  min-height:100%;
}
body{
  margin:0;
  font-family:var(--sans);
  color:var(--text);
  background:
    radial-gradient(900px 380px at 15% 0%, rgba(0,0,255,.10), transparent 60%),
    radial-gradient(900px 380px at 85% 0%, rgba(138,99,210,.12), transparent 60%),
    var(--bg);
}

.app{
  width:100%;
  max-width:100vw;
  margin:0;
  padding: calc(env(safe-area-inset-top) + 10px) 14px calc(env(safe-area-inset-bottom) + 18px);
}

/* Sticky top */
.top{
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 0 10px;
  background: linear-gradient(to bottom, rgba(246,247,251,.92), rgba(246,247,251,.70), transparent);
  backdrop-filter: blur(14px);
  overflow: visible;
  width:100%;
}
.topCover{
  position:absolute;
  left:0;
  right:0;
  top:-120px;
  width:100%;
  height:260px;
  transform:none;
  border-radius:999px;
  background:
    radial-gradient(60% 80% at 50% 50%, rgba(138,99,210,.55), rgba(138,99,210,.18) 45%, transparent 70%),
    radial-gradient(45% 60% at 50% 55%, rgba(92,59,208,.55), transparent 70%);
  filter: blur(2px);
  pointer-events:none;
  z-index:0;
}
[data-theme="dark"] .top{
  background: linear-gradient(to bottom, rgba(7,8,18,.92), rgba(7,8,18,.72), transparent);
}

.nav{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 2px;
}
.nav,
.controls{
  position:relative;
  z-index:1;
}
.brand{
  display:flex; align-items:center; gap:10px; min-width:0;
}
.logo{
  width:52px;
  height:65px;
  border-radius:18px;
  object-fit:contain;
  object-position:center;
  flex:0 0 auto;
  display:block;
}
.titles{ min-width:0; }
.titles h1{
  margin:0;
  font-size:18px;
  line-height:1.15;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.titles p{
  margin:2px 0 0;
  font-size:12px;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.actions{ display:flex; gap:10px; }
.howBtn{
  height:44px;
  padding:0 14px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.62);
  backdrop-filter: blur(10px);
  display:inline-flex;
  align-items:center;
  gap:8px;
  color:var(--text);
  font-size:12px;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.howBtn .qIcon{
  width:18px;height:18px;
  border-radius:999px;
  border:1px solid var(--border);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:12px;
  font-weight:800;
  color:var(--muted);
  background: var(--chipBg);
}
[data-theme="dark"] .howBtn{ background: rgba(12,14,26,.70); }
.iconBtn{
  width:44px; height:44px;
  border-radius: var(--r14);
  border:1px solid var(--border);
  background: rgba(255,255,255,.62);
  backdrop-filter: blur(10px);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
[data-theme="dark"] .iconBtn{ background: rgba(12,14,26,.70); }

.moon{
  width:18px;height:18px;border-radius:999px;
  background:
    radial-gradient(circle at 35% 35%, rgba(255,255,255,.0) 55%, rgba(0,0,0,.25) 56%),
    linear-gradient(135deg, rgba(0,0,255,.35), rgba(138,99,210,.35));
  border:1px solid rgba(0,0,0,.08);
}
[data-theme="dark"] .moon{ border-color: rgba(255,255,255,.10); }

.sliders{
  width:18px;height:18px;
  background:
    linear-gradient(var(--text),var(--text)) 50% 25%/100% 2px no-repeat,
    linear-gradient(var(--text),var(--text)) 50% 50%/100% 2px no-repeat,
    linear-gradient(var(--text),var(--text)) 50% 75%/100% 2px no-repeat,
    radial-gradient(circle, var(--text) 55%, transparent 56%) 28% 25%/10px 10px no-repeat,
    radial-gradient(circle, var(--text) 55%, transparent 56%) 68% 50%/10px 10px no-repeat,
    radial-gradient(circle, var(--text) 55%, transparent 56%) 38% 75%/10px 10px no-repeat;
  opacity:.85;
}

/* Controls */
.controls{ margin-top:10px; display:flex; flex-direction:column; gap:10px; }

.search{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 12px 12px;
  min-height:44px;
  border:1px solid var(--border);
  border-radius: var(--r22);
  background: rgba(255,255,255,.70);
  backdrop-filter: blur(10px);
}
[data-theme="dark"] .search{ background: rgba(12,14,26,.72); }
.search input{
  border:0; outline:none; background:transparent;
  width:100%;
  font-size:14px;
  color:var(--text);
}
.magnifier{
  width:16px;height:16px;
  border:2px solid var(--muted);
  border-radius:999px;
  position:relative;
  flex:0 0 auto;
  opacity:.8;
}
.magnifier:after{
  content:"";
  position:absolute;
  width:9px;height:2px;
  background:var(--muted);
  right:-8px; bottom:-3px;
  transform: rotate(45deg);
  border-radius:2px;
  opacity:.8;
}

.row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.row > .seg,
.row > .sortPicker{
  flex:1 1 0;
}

.seg{
  display:inline-flex;
  gap:6px;
  padding:0;
  border-radius:999px;
  border:1px solid var(--border);
  background: var(--chipBg);
  overflow:hidden;
  height:44px;
  align-items:stretch;
}
.seg button{
  min-height:40px;
  height:100%;
  padding: 0 10px;
  border:0;
  border-radius:999px;
  background:transparent;
  color:var(--muted);
  font-size:12px;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
  flex:1 1 0;
  text-align:center;
}
.seg button.active{
  color:var(--text);
  background: linear-gradient(135deg, rgba(0,0,255,.16), rgba(138,99,210,.16));
  border:0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
[data-theme="dark"] .seg button.active{ border-color: rgba(255,255,255,.10); }

.sortPicker{
  min-height:40px;
  height:44px;
  padding: 0;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.62);
  backdrop-filter: blur(10px);
  display:inline-flex;
  align-items:center;
  gap:8px;
  user-select:none;
  font-size:12px;
  color:var(--muted);
  white-space:nowrap;
  -webkit-tap-highlight-color: transparent;
}
[data-theme="dark"] .sortPicker{ background: rgba(12,14,26,.72); }
.sortPicker label{
  font-size:12px;
  color:var(--muted);
}
.sortPicker select{
  appearance:none;
  -webkit-appearance:none;
  border:0;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    transparent;
  background-position:
    calc(100% - 14px) 52%,
    calc(100% - 8px) 52%,
    0 0;
  background-size:6px 6px, 6px 6px, 100% 100%;
  background-repeat:no-repeat;
  color:var(--text);
  font-family: var(--mono);
  font-size:11px;
  padding:6px 26px 6px 12px;
  border-radius:999px;
  cursor:pointer;
  height:100%;
  width:100%;
}
.sortPicker select:focus{ outline:none; box-shadow: 0 0 0 2px rgba(138,99,210,.20); }

/* Responsive */
@media (max-width: 520px){
  .app{
    max-width: 100%;
    margin: 0;
    padding: calc(env(safe-area-inset-top) + 8px) 0 calc(env(safe-area-inset-bottom) + 14px);
  }
  .nav{ padding:0 8px; }
  .controls{ padding:0 8px; }
  .list{ padding:0 8px; }
  .nav{ flex-wrap:wrap; gap:10px; }
  .brand{ gap:8px; }
  .logo{ width:48px; height:48px; border-radius:16px; }
  .titles h1{ font-size:16px; }
  .row{ flex-direction:row; align-items:center; flex-wrap:nowrap; }
  .seg{ flex:1 1 0; justify-content:space-between; min-height:44px; height:44px; padding:0; }
  .seg button{ flex:1 1 auto; padding:0 8px; }
  .sortPicker{ flex:1 1 0; justify-content:flex-end; min-height:44px; height:44px; padding:0; }
  .sortPicker label{ display:none; }
  .sortPicker select{ flex:1 1 auto; min-width:0; height:100%; }
  .cell{ align-items:center; }
  .metricsLine{ gap:6px; }
  .kpi{ padding:6px 8px; }
  .meta{ flex:0 0 48px; }
}

@media (max-width: 360px){
  .logo{ width:44px; height:44px; border-radius:14px; }
  .titles h1{ font-size:15px; }
  .name{ font-size:14px; }
  .domain{ font-size:11px; }
  .seg button{ min-height:36px; }
  .sortPicker{ min-height:36px; }
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 380px at 15% 0%, rgba(0,0,255,.10), transparent 60%),
    radial-gradient(900px 380px at 85% 0%, rgba(138,99,210,.12), transparent 60%),
    #F6F7FB;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

@media (prefers-color-scheme: dark) {
  .loading-screen {
    background:
      radial-gradient(900px 380px at 15% 0%, rgba(0,0,255,.10), transparent 60%),
      radial-gradient(900px 380px at 85% 0%, rgba(138,99,210,.12), transparent 60%),
      #070812;
  }
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-screen-content {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.6s ease;
}

.loading-logo {
  width: 120px;
  height: 150px;
  animation: logoPulse 2s ease-in-out infinite, logoGlow 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
}

@media (prefers-color-scheme: dark) {
  .loading-logo {
    filter: drop-shadow(0 0 30px rgba(102, 126, 234, 0.5));
  }
}

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

@keyframes logoPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes logoGlow {
  0%, 100% {
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 40px rgba(255, 255, 255, 0.5));
  }
}

[data-theme="dark"] @keyframes logoGlow {
  0%, 100% {
    filter: drop-shadow(0 0 30px rgba(102, 126, 234, 0.5));
  }
  50% {
    filter: drop-shadow(0 0 50px rgba(240, 147, 251, 0.7));
  }
}

/* List */
.list{ margin-top:12px; display:flex; flex-direction:column; gap:10px; }

/* Card link wrapper for clickable cards */
.card-link{
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card{
  border:1px solid var(--border);
  border-radius: var(--r22);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow:hidden;
}

/* Compact cell */
.cell{
  padding: 10px;
  display:flex;
  gap:10px;
  align-items:center;
}

.rank{
  width:auto;
  flex:0 0 auto;
  font-family: var(--mono);
  color:var(--muted);
  font-size:12px;
  text-align:center;
}
.meta{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
  flex:0 0 44px;
}
.icon{
  width:40px;height:40px;
  border-radius: 14px;
  border:1px solid var(--border);
  background:
    radial-gradient(circle at 30% 30%, rgba(0,0,255,.20), transparent 55%),
    radial-gradient(circle at 70% 70%, rgba(138,99,210,.26), transparent 55%),
    rgba(0,0,0,.03);
  flex:0 0 auto;
  object-fit: cover;
}

.icon-placeholder{
  width:40px;height:40px;
  border-radius: 14px;
  border:1px solid var(--border);
  background:
    radial-gradient(circle at 30% 30%, rgba(0,0,255,.20), transparent 55%),
    radial-gradient(circle at 70% 70%, rgba(138,99,210,.26), transparent 55%),
    rgba(0,0,0,.03);
  flex:0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
}

.main{
  flex:1 1 auto;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:4px;
}

.line1{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}
.nameWrap{
  min-width:0;
  display:flex;
  align-items:center;
  gap:8px;
}
.name{
  font-size:15px;
  font-weight:750;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.cat{
  font-size:11px;
  color:var(--muted);
  border:1px solid var(--border);
  background: var(--chipBg);
  padding:4px 8px;
  border-radius:999px;
  text-transform: lowercase;
}

/* Metrics inline: Score | Reach | Activity */
.metricsLine{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  align-items:center;
}
.kpi{
  display:inline-flex;
  align-items:baseline;
  gap:6px;
  border:1px solid var(--border);
  background: var(--chipBg);
  border-radius: 999px;
  padding: 5px 9px;
  font-family: var(--mono);
  line-height:1;
}
.kpi b{
  font-size:13px;
  font-weight:900;
  color:var(--text);
}
.kpi span{
  font-size:10px;
  color:var(--muted);
  letter-spacing:.1px;
}

/* Right arrow */
.arrow{
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.arrow::before{
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  transform: rotate(45deg);
  right: 4px;
}

.arrow::after{
  content: "";
  position: absolute;
  width: 10px;
  height: 2px;
  background: var(--muted);
  right: 2px;
}

.empty{
  padding: 18px 12px;
  color: var(--muted);
  text-align:center;
  font-size:13px;
}

.error{
  padding: 18px 12px;
  color: var(--muted);
  text-align:center;
  font-size:13px;
  display:flex;
  flex-direction:column;
  gap:12px;
  align-items:center;
}

.loading{
  margin-top:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.skeleton-card{
  border:1px solid var(--border);
  border-radius: var(--r22);
  background: var(--panel);
  height:100px;
  animation: pulse 1.5s ease-in-out infinite;
}

.loadingMore{
  margin: 12px auto 6px;
  display:flex;
  align-items:center;
  gap:8px;
  justify-content:center;
  color:var(--muted);
  font-size:12px;
}
.spinner{
  width:16px;height:16px;
  border-radius:999px;
  border:2px solid rgba(138,99,210,.25);
  border-top-color: rgba(138,99,210,.9);
  animation: spin .9s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }
@keyframes pulse{
  0%, 100%{ opacity:1; }
  50%{ opacity:.5; }
}

/* Bottom Sheet */
.sheetBackdrop{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.35);
  display:none;
  z-index:200;
}
.sheetBackdrop.open{ display:block; }

.sheet{
  position:fixed;
  left:50%;
  transform: translateX(-50%);
  bottom:-100%;
  width:min(520px, 100%);
  background: var(--panel);
  border:1px solid var(--border);
  border-bottom:0;
  border-top-left-radius:22px;
  border-top-right-radius:22px;
  box-shadow: var(--shadow);
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 14px);
  transition: bottom .22s ease;
  z-index:201;
}
.sheet.open{ bottom:0; }
.grab{
  width:46px;height:5px;border-radius:999px;
  background: var(--chipBg);
  border:1px solid var(--border);
  margin: 6px auto 10px;
}
.sheetHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 6px 0 10px;
}
.sheetHeader b{ font-size:14px; }
.sheetHeader button{
  border:0;background:transparent;
  color:var(--muted);
  font-size:13px;
  cursor:pointer;
  min-height:40px;
  padding: 0 6px;
}

.section{
  border-top:1px solid var(--border);
  padding: 12px 0;
}
.section:first-of-type{ border-top:0; padding-top:6px; }
.sectionTitle{
  font-size:12px;
  color:var(--muted);
  font-weight:800;
  letter-spacing:.2px;
  margin-bottom:10px;
}
.chipRow{ display:flex; gap:8px; flex-wrap:wrap; }
.chipBtn{
  min-height:38px;
  padding: 0 12px;
  border-radius:999px;
  border:1px solid var(--border);
  background: var(--chipBg);
  color:var(--muted);
  cursor:pointer;
  font-size:12px;
  text-transform: lowercase;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.chipBtn.active{
  color:var(--text);
  background: linear-gradient(135deg, rgba(0,0,255,.16), rgba(138,99,210,.16));
}

.sheetActions{ display:flex; gap:10px; margin-top: 6px; }
.btn{
  flex:1 1 auto;
  min-height:44px;
  border-radius:16px;
  border:1px solid var(--border);
  cursor:pointer;
  font-size:13px;
  font-weight:800;
}
.btnPrimary{
  background: linear-gradient(135deg, rgba(0,0,255,.18), rgba(138,99,210,.18));
  color:var(--text);
}
.btnGhost{
  background: transparent;
  color:var(--muted);
}

/* How It Works modal */
.modalBackdrop{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.45);
  display:none;
  z-index:220;
}
.modalBackdrop.open{ display:block; }
.modal{
  position:fixed;
  left:50%;
  top:50%;
  transform: translate(-50%,-50%);
  width:min(560px, 92vw);
  max-height:80vh;
  overflow:auto;
  background: var(--panel);
  border:1px solid var(--border);
  border-radius:22px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  z-index:221;
  display:none;
}
.modal.open{ display:block; }
.modalHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding-bottom:8px;
  border-bottom:1px solid var(--border);
}
.modalHeader b{ font-size:14px; }
.modalClose{
  border:0;
  background:transparent;
  color:var(--muted);
  font-size:13px;
  cursor:pointer;
  min-height:32px;
  padding:0 6px;
}
.modalBody{
  padding-top:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
  font-size:13px;
  color:var(--text);
  line-height:1.45;
}
.modalBody h4{
  margin:6px 0 0;
  font-size:13px;
}
.modalBody p{
  margin:0;
  color:var(--muted);
}
